Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách đặt font cho Text trong Tkinter

Tkinter có nhiều phương thức tích hợp tùy chỉnh widget. Tùy chỉnh font-property của Text widget bằng font('font-family',font-size, 'style'). Tuple khai báo trong constructor Text.

Ví dụ

Xem ví dụ tạo text widget với font tùy chỉnh.
#Import tkinter library
from tkinter import *
from tkinter import ttk
#Tạo instance tkinter frame
win= Tk()
#Đặt geometry
win.geometry("750x250")
#Định nghĩa text widget với font-property
text= Text(win, height=15, font=('Times New Roman',17,'bold'))
text.insert(INSERT, "Hey Folks!, Welcome to TutorialsPoint!")
text.pack()
win.mainloop()

Kết quả

Chạy mã hiển thị cửa sổ chứa text widget. Văn bản tùy chỉnh bằng font.

Cách đặt font cho Text trong Tkinter