您知道是否可以自動調整視窗的寬度以匹配其中文本的長度?例如,
很適合,但在
文本中走出了視窗。
或者如果更好,是否可以換行以適應視窗中的文本?
PS:要在我的視窗中插入文本,我正在使用ttk.Label()
uj5u.com熱心網友回復:
嘗試使用wraplength標簽的屬性
import tkinter as tk
root = tk.Tk()
tk.Label(root,width=40,text="This is going to be far too long to fit on the screen that I have chosen").grid()
tk.Label(root,width=40,wraplength=100,text="This is going to be far too long to fit on the screen that I have chosen but will wrap").grid()
root.mainloop()
這種行為對我來說似乎有點不一致,但它應該包含 40 個字符。
uj5u.com熱心網友回復:
如果您不想將視窗的大小顯式設定為特定大小,那么您可以這樣做
window.geometry("")
它會自動調整大小以適應視窗的內容
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/446471.html
