Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Tkinter(Python 3)中设置按钮宽度_Python_Python 3.x_Button_Tkinter_Window - Fatal编程技术网

如何在Tkinter(Python 3)中设置按钮宽度

如何在Tkinter(Python 3)中设置按钮宽度,python,python-3.x,button,tkinter,window,Python,Python 3.x,Button,Tkinter,Window,我想用Python3制作一个简单的测验程序,但我不知道如何使按钮达到我想要的最大宽度。我使用Python3和TKinter模块来创建窗口和所有按钮 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

我想用Python3制作一个简单的测验程序,但我不知道如何使按钮达到我想要的最大宽度。我使用Python3和TKinter模块来创建窗口和所有按钮

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()
代码生成如下窗口:

使用Grid.rowconfigure、Grid.columnconfigure和sticky=E+W


简单的谷歌搜索会给你正确的答案问你自己sticky=W做什么?为了学究,对于这个特定的问题,sticky值不需要包括N和S。@BryanOakley谢谢。这是一个表格解决方案。
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()