我的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()

最佳答案

只需将grid geometry管理器的sticky选项添加到以下行

self.fontProceed.grid(row=2, column=0, columnspan=2)


导致

self.fontProceed.grid(row=2, column=0, columnspan=2, sticky='NSEW')


python - Python 3 Tkinter:网格列跨度被忽略-LMLPHP

关于python - Python 3 Tkinter:网格列跨度被忽略,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32293919/

10-09 07:28