我已经使用python
工作了一周,与Tkinter
更短,所以如果我的问题是典型的,很抱歉。
我想为示波器编写一个简单的GUI。但是,我遇到了一个问题,那就是如何将按钮的大小适配到其他按钮的大小。这是我所达到的程度(截图)。
你可能会注意到trigger
和horizontal
按钮的大小小于所有channel
组的大小。那么,如何将它们的大小恰好适配到channel
组的大小。这是我的一段代码。
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
startLabel = tk.Label(self,
text="Start page")
startLabel.pack(side="top")
quitGroup = tk.Frame(self)
quitGroup.pack(side="bottom")
quitButton = tk.Button(quitGroup, text="Quit",
command=quit,
bg="pink")
quitButton.grid(pady=10)
channelGroup = tk.Frame(self)
channelGroup.pack(side=tk.LEFT)
chLabel = tk.Label(channelGroup,
text="Channel group")
chLabel.grid(pady=10)
ch1Button = tk.Button(channelGroup, text="CH1 Settings",
command=lambda: controller.show_frame("CH1"))
ch1Button.grid(row=1, column=0)
ch2Button = tk.Button(channelGroup, text="CH2 Settings",
command=lambda: controller.show_frame("CH2"))
ch2Button.grid(row=2, column=0)
ch3Button = tk.Button(channelGroup, text="CH3 Settings",
command=lambda: controller.show_frame("CH3"))
ch3Button.grid(row=3, column=0)
ch4Button = tk.Button(channelGroup, text="CH4 Settings",
command=lambda: controller.show_frame("CH4"))
ch4Button.grid(row=4, column=0)
triggerGroup = tk.Frame(self)
triggerGroup.pack(side=tk.LEFT)
trigLabel = tk.Label(triggerGroup,
text="Trigger group")
trigLabel.grid(pady=10)
trigButton = tk.Button(triggerGroup, text="Trigger Settings",
command=lambda: controller.show_frame("Trigger"))
trigButton.grid(row=1, column=0)
trigButton.grid(ipady=43)#43? What?
horizGroup = tk.Frame(self)
horizGroup.pack(side=tk.LEFT)
horizLabel = tk.Label(horizGroup,
text="Horizontal group")
horizLabel.grid(pady=10)
horizButton = tk.Button(horizGroup,
text="Horizontal settings",
command=lambda: controller.show_frame("Horizontal"))
horizButton.grid(row=1, column=0)
horizButton.grid(ipady=43)#you again ...
如果这些按钮在不同的框架中,是否有可能?我想保持原样。
Channel group
和Trigger group
。 在这些组中有按钮:分别为四个和一个。如果您查看CH1设置
按钮的上限以及触发器设置
按钮的相同限制,则会注意到它们不在同一水平线上。 - LRDPRDXpack
的fill
、anchor
和expand
选项进行实验吗? - Bryan Oakley