如何在 Tkinter 中更改標籤上的文字大小?
Tkinter 中的標籤 控制元件用於在 Tkinter 應用程式中顯示文字和影像。為了更改標籤控制元件的屬性,如其字型屬性、顏色、背景顏色、前景顏色等,你可以使用configure()方法。
如果要更改“標籤”控制元件中文字的大小,那麼可以在控制元件建構函式中配置font=('字型族 字型大小 樣式')屬性。
示例
# Import the required libraries
from tkinter import *
import tkinter.font as tkFont
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the tkinter window
win.geometry("700x350")
def font_style():
label.config(font=('Helvetica bold', 26))
# Create a Label
label = Label(win, text="Click the Button to Change the Font Style.", font=('Times', 24))
label.pack()
b1 = Button(win, text="Change the Label Size", command=font_style)
b1.pack()
win.mainloop()輸出
當你執行以上程式碼時,它將顯示一個帶有標籤控制元件和一個按鈕的視窗,該按鈕用於更改標籤的字型樣式。

現在,單擊“更改標籤大小”按鈕,它將修改標籤的字型樣式。

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP