我想顯示兩個相鄰的標簽框,如下圖 Picture1所示。你知道怎么做嗎?
當我嘗試標簽框時,不要留在原地,而是將其調整為文本。
這就是我想要的,但是標簽框中有 txt 中心
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry('600x200')
style = ttk.Style(root)
root.tk.call('source', 'azure dark.tcl')
style.theme_use('azure')
lf1 = ttk.Labelframe(root, text='Labeltxt1', width=300,height=100)
lf1.grid(row=0,column=0)
lf2 = ttk.Labelframe(root, text='Labeltxt2', width=300,height=100)
lf2.grid(row=0,column=1)
root.mainloop()
這就是我得到的:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry('600x200')
style = ttk.Style(root)
root.tk.call('source', 'azure dark.tcl')
style.theme_use('azure')
lf1 = ttk.Labelframe(root, text='Labeltxt1', width=300,height=100)
lf1.grid(row=0,column=0)
lf2 = ttk.Labelframe(root, text='Labeltxt2', width=300,height=100)
lf2.grid(row=0,column=1)
lb1= ttk.Label(lf1, text='txt1')
lb1.pack()
lb2= ttk.Label(lf2, text='txt2')
lb2.pack()
root.mainloop()
標簽框不填充視窗的寬度。
希望我已經足夠清楚了。謝謝您的幫助。
uj5u.com熱心網友回復:
您需要告訴布局管理器這兩個Labelframe使用root.rowconfigure()和填充所有可用空間root.columnconfigure()。還需要sticky='nsew'在.grid(...). width在這種情況下,您不需要height指定Labelframe.
...
root.rowconfigure(0, weight=1)
root.columnconfigure((0,1), weight=1)
lf1 = ttk.Labelframe(root, text='Labeltxt1')
lf1.grid(row=0, column=0, sticky='nsew')
lf2 = ttk.Labelframe(root, text='Labeltxt2')
lf2.grid(row=0, column=1, sticky='nsew')
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/441029.html
標籤:python-3.x tkinter ttk
