以下代码中忽略了我的grid
columnspan
。 "Ok"
按钮不会占据width
。
class Arshi(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.fontOption = tk.Toplevel()
self.selectFont = tk.Label(self.fontOption, text="Select Font: ", font=("Courier New", 9))
self.selectFont.grid(row=0, columnspan=1)
self.selectedFont = tk.StringVar()
self.fontComboBox = ttk.Combobox(self.fontOption, textvariable=self.selectedFont)
self.fontComboBox.grid(row=0, column=1, columnspan=1)
self.selectFontSize = tk.Label(self.fontOption, text="Font Size: ", font=("Courier New", 9))
self.selectFontSize.grid(row=1, columnspan=1)
self.selectedFontSize = tk.StringVar()
self.fontSizeComboBox = ttk.Combobox(self.fontOption, textvariable=self.selectedFontSize)
self.fontSizeComboBox.grid(row=1, column=1, columnspan=1)
self.fontProceed = tk.Button(self.fontOption, text="Ok", font=("Courier New", 9))
self.fontProceed.grid(row=2, column=0, columnspan=2)
if __name__ == "__main__":
root = tk.Tk()
root.title("Arshi")
root.geometry("1024x600")
window = Arshi(root).pack(side="top", fill="both", expand=True)
root.mainloop()
答案 0 :(得分:3)
只需将grid geometry经理的sticky
选项添加到以下行
self.fontProceed.grid(row=2, column=0, columnspan=2)
导致
self.fontProceed.grid(row=2, column=0, columnspan=2, sticky='NSEW')