Python 3 Tkinter:Grid columnspan被忽略

时间:2015-08-30 06:32:55

标签: python python-3.x tkinter

以下代码中忽略了我的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()

1 个答案:

答案 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')

enter image description here

相关问题