我有这个代码
class App(object):
def __init__(self):
self.root = Tk()
self.root.attributes('-zoomed', True)
f1 = Frame(self.root, bd=1, bg="green", relief=SUNKEN)
f2 = Frame(self.root, bd=1, bg="red", relief=SUNKEN)
f3 = Frame(self.root, bd=1, bg="blue", relief=SUNKEN)
split = 0.5
f1.place(relx=0, relheight=1, relwidth=split)
f2.place(relx=split, relheight=1, relwidth=1.0 - split)
f3.place(height=50, width=self.screen_width)
app = App()
app.root.mainloop()
Run Code Online (Sandbox Code Playgroud)
如何将蓝框放在窗口/屏幕的底部?
我知道您特别询问过,但老实说,除非在极少数情况下,否则place您不应该使用。使用和place来实现您想要实现的布局非常简单。gridpack
使用pack:
f3.pack(side="bottom", fill="x")
f1.pack(side="left", fill="both", expand=True)
f2.pack(side="right", fill="both", expand=True)
Run Code Online (Sandbox Code Playgroud)
使用grid:
# row zero takes up all extra vertical space
# column 0 and column 1 take an equal amount of all horizontal space
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(0, weight=1)
self.root.grid_columnconfigure(1, weight=1)
f1.grid(row=0, column=0, sticky="nsew")
f2.grid(row=0, column=1, sticky="nsew")
f3.grid(row=1, column=0, columnspan=2, sticky="ew")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13243 次 |
| 最近记录: |