问题
I have this code
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()
and the output is this
How to put the blue frame to the bottom of the window/screen?
回答1:
I know you specifically asked about place
, but honestly, you should not use place
except in very rare circumstances. The layout you're trying to achieve is very easy with both grid
and pack
.
Using pack
:
f3.pack(side="bottom", fill="x")
f1.pack(side="left", fill="both", expand=True)
f2.pack(side="right", fill="both", expand=True)
Using 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")
来源:https://stackoverflow.com/questions/37017472/python-tkinter-place-put-frame-to-the-bottom