如何对齐 tkinter 小部件? [英] How to align tkinter widgets?
本文介绍了如何对齐 tkinter 小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何对齐我的Radiobutton
?我可以向 test4
添加空格,但该解决方案似乎不合适.这是目前的样子——正如你所看到的 text111111
有额外的字符.我试过使用 padx
.
How do I align my Radiobutton
s? I can add spaces to test4
but that solution doesn't seem proper. Here's what it looks like at the moment—as you can see text111111
has extra chars. I've tried using padx
.
我的代码:
from tkinter import *
class GUI:
def __init__(self, master):
self.iconnum = IntVar()
self.master = master
self.master.title('test')
self.master.resizable(width=False, height=False)
self.master.maxsize(500, 250)
self.master.minsize(500, 250)
self.test1 = Radiobutton(master, text="test11111111", variable=self.iconnum,
value=1, )
self.test2 = Radiobutton(master, text="test2", variable=0, value=2, )
self.test3 = Radiobutton(master, text="test3", variable=0, value=3, )
self.test4 = Radiobutton(master, text="test4", variable=0, value=4)
self.test1.grid(row=2, columnspan=1)
self.test2.grid(row=2, columnspan=2)
self.test3.grid(row=2, column=1)
self.test4.grid(row=3, columnspan=1)
self.Checker = Radiobutton(master, text="test5", indicatoron=0, height=1, width=35,
value=0, command=self.icon_switcher) #var=Selection)
self.Turbo = Radiobutton(master, text="test6", indicatoron=0, height=1, width=35,
value=1, command=self.icon_switcher) #var#=Selection)
self.Checker.grid(row=1)
self.Turbo.grid(row=1, column=1, )
def icon_switcher(self):
print("Hello")
root = Tk()
gui = GUI(root)
root.mainloop()
推荐答案
你可以在你的 .grid
中使用 sticky=W
来让你的所有按钮对齐左侧.您还可以包含 pady = 20
以使其不会一直向左移动.
You can use sticky=W
inside your .grid
for all your buttons to make them align on the left side. And you can also include pady = 20
to make it not go all the way to the left.
这篇关于如何对齐 tkinter 小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文