-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

2
  • 3
    simple google search will give you the correct answer Commented Feb 25, 2016 at 9:42
  • 2
    Ask yourself "what does sticky=W do?" Commented Feb 25, 2016 at 12:21

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

2 Comments

to be pedantic, the sticky value doesn't need to include N and S for this specific question.
@BryanOakley Thank you.it was for a table solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.