[英]Frame of fixed size staying at the bottom of the window
我正在使用 Tk GUI,我希望我的窗口被分成 2 帧,类似这样:
import tkinter as tk
root = tk.Tk()
root.geometry('1000x800')
df_frame = tk.LabelFrame(root)
df_frame.place(relwidth = 1, height = 720)
open_file_frame = tk.LabelFrame(root)
open_file_frame.place(x = 0, y = 720, relwidth = 1, height = 80)
root.mainloop()
我的问题是我不知道如何使它适应窗口的大小。 如果用户放大窗口的大小,我希望第二个框架留在底部,第一个框架相应地放大。 在此先感谢您的帮助。
尝试使用网格管理器来控制调整大小并使用 rowconfigure 和 columnconfigure 来控制对象如何更改大小。
另外LabelFrames
需要包含一些对象,在这段代码中我使用了Buttons
。
import tkinter as tk
def flexx( o, r = 0, c = 0, rw = 1, cw = 1):
o.rowconfigure(r, weight = rw)
o.columnconfigure(c, weight = cw)
root = tk.Tk()
root.geometry('1000x800')
# make contents of root resizable
flexx(root)
df_frame = tk.LabelFrame(root)
df_frame.grid(sticky = tk.NSEW)
# You need some object in labelframe
tk.Button(df_frame, text = "Any object to occupy labelframe").grid(sticky = tk.NSEW)
# make contents of df_frame resizable
flexx(df_frame)
open_file_frame = tk.LabelFrame(root)
open_file_frame.grid(sticky = tk.NSEW)
# You need some object in labelframe
tk.Button(open_file_frame, text = "Any other object").grid(sticky = tk.NSEW)
# make contents of open_file_frame resizable
flexx(open_file_frame)
root.mainloop()
您可以结合relheight
和height
选项来控制顶部框架的高度。
并结合rely
和y
选项将底部框架放在窗口底部:
import tkinter as tk
root = tk.Tk()
root.geometry('1000x800')
df_frame = tk.LabelFrame(root)
# frame_height = window_height - 80
df_frame.place(relwidth=1, relheight=1, height=-80)
open_file_frame = tk.LabelFrame(root)
# frame y position = 80 pixel from the bottom
open_file_frame.place(rely=1, y=-80, relwidth=1, height=80)
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.