gpt4 book ai didi

python 3 Tkinter : Grid columnspan ignored

转载 作者:太空宇宙 更新时间:2023-11-04 10:21:03 24 4
gpt4 key购买 nike

我的 grid columnspan 在以下代码中被忽略了。 “确定” 按钮未占据整个宽度

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 geometrysticky 选项经理到以下行

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

导致

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

enter image description here

关于 python 3 Tkinter : Grid columnspan ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32293919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com