我的问题是:输出应该显示 2 个侧边栏(第 0 列和第 2 列),其中包含内容标签和条目以及一个中央窗口(第 1 列),比中间的其他侧边栏大得多。但中间的列总是出现在右侧,并且作为一个非常小的框架。请帮忙。
我的代码和图片:
import tkinter as tk, tkinter.ttk as ttk
root = tk.Tk()
root.title("THE FRIDGER")
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(2, weight=1)
#prepared data
dflt = dict(fg="white", bg="black")
pads = dict(pady=4, padx=4)
#header frame
header = tk.Frame(root, bg="black")
header.grid(row=0, column=0, columnspan=3, sticky="nsew")
for i in range(2):
header.grid_columnconfigure(i, weight=1)
#header labels
tk.Label(header, text="Fridge", **dflt).grid(column=0, row=0, **pads)
tk.Label(header, text="Recipes", **dflt).grid(column=1, row=0, **pads)
#separator
s = ttk.Style()
s.configure('custom.TSeparator', background='blue')
ttk.Separator(root, style='custom.TSeparator').grid(row=1, column=0, columnspan=3, sticky="ew")
#left side content
l_content = tk.Frame(root, bg="black")
l_content.grid(row=2, column=0, sticky="nsew")
tk.Label(l_content, text="Content:", **dflt).grid(column=0, row=0, sticky=tk.W)
l_query = tk.Entry(l_content, width=36, relief=tk.FLAT, bg = "white", fg = "black")
l_query.grid(column=0, row=1, sticky=tk.W)
#right side content
r_content = tk.Frame(root, bg="black")
r_content.grid(row=2, column=2, sticky="nsew")
tk.Label(r_content, text="Content:", **dflt).grid(column=0, row=2, sticky=tk.W)
r_query = tk.Entry(r_content, width=36, relief=tk.FLAT, bg = "white", fg = "black")
r_query.grid(column=0, row=3, sticky=tk.W)
#middle content
m_content = tk.Frame(root, bg="white")
m_content.grid(row=2, column=1, sticky="nsew")
tk.Label(m_content, text="This should appear in the middle", **dflt).grid(column=0, row=2, sticky=tk.W)
m_content.grid_columnconfigure(1, weight = 1)
root.mainloop()
开心每一天1111
慕桂英3389331
相关分类