-5

I would like to make a simple quiz program in python 3 but I can not find out how to make a button go the full width I want it to. I am using python 3 and the TKinter module to make the window and all the buttons.

from tkinter import *

root = Tk()

que_labl = Label(root, text='Question')
choice1 = Button(root, text='Choice one')
choice2 = Button(root, text='Choice one plus one')
choice3 = Button(root, text='Choice 3')
choice4 = Button(root, text='Choice eight divided by 2')

que_labl.grid(row=0, columnspan=2)
choice1.grid(row=2, column=0, sticky=W)
choice2.grid(row=2, column=1, sticky=W)
choice3.grid(row=3, column=0, sticky=W)
choice4.grid(row=3, column=1, sticky=W)

root.mainloop()

The code makes a window like this:

enter image description here

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

1

Use Grid.rowconfigure(), Grid.columnconfigure() and sticky=E+W.

from Tkinter import *

root = Tk()
#Configure line 0 and 1
Grid.rowconfigure(root, 0, weight=1)
Grid.rowconfigure(root, 1, weight=1)

#Configure column 0 and 1
Grid.columnconfigure(root, 0, weight=1)
Grid.columnconfigure(root, 1, weight=1)

que_labl = Label(root, text='Question')
choice1 = Button(root, text='Choice one')
choice2 = Button(root, text='Choice one plus one')
choice3 = Button(root, text='Choice 3')
choice4 = Button(root, text='Choice eight divided by 2')

que_labl.grid(row=0, columnspan=2)
choice1.grid(row=2, column=0, sticky=E+W)
choice2.grid(row=2, column=1, sticky=E+W)
choice3.grid(row=3, column=0, sticky=E+W)
choice4.grid(row=3, column=1, sticky=E+W)

root.mainloop()
Kenly
  • 24,317
  • 7
  • 44
  • 60