如何在 Tkinter 中新增標籤寬度?
標籤控制元件用於在應用程式中顯示文字和影像。標籤控制元件的大小取決於許多因素,例如標籤文字的寬度、高度和字型大小。高度和寬度定義了標籤控制元件在視窗中應如何顯示。
要設定標籤控制元件的寬度,我們應該使用變數宣告標籤控制元件。用變數例項化標籤控制元件允許使用者新增/編輯標籤控制元件的屬性。
示例
# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Add a Label widget label=Label(win, text="A Label widget is used to display text " "and images in an application.", font=('Times 14'), width=100) label.pack() win.mainloop()
輸出
如果你執行以上程式碼,它將顯示一個視窗,其中包含一個具有特定寬度的標籤文字。
廣告