[英]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.