如何在 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()

輸出

如果你執行以上程式碼,它將顯示一個視窗,其中包含一個具有特定寬度的標籤文字。

更新日期: 19-Jun-2021

2K+ 瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始
廣告