Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีใช้ Unicode และ Special Characters ใน Tkinter

บางครั้งเราต้องการเพิ่ม Unicode และ Special Character ในแอปพลิเคชัน Tkinter เราสามารถเพิ่ม Unicode characters ใน Label หรือ Widget ได้โดยการต่อสตริงด้วยลายเซ็น u '/' คุณสามารถหารายการ Unicode characters ทั้งหมดได้จากที่นี่

ในตัวอย่างนี้ เราจะเพิ่ม Unicode character ใน Button widget

ตัวอย่าง

# Import the required Libraries
from tkinter import *

# Create an instance of tkinter frame
win = Tk()
win.geometry("700x200")

# Create a button
Button(win, text='Click' + u'\u01CF', font=('Poppins bold', 10)).pack(pady=20)

# Keep running the window or frame
win.mainloop()

ผลลัพธ์

การรันโค้ดข้างต้นจะสร้างปุ่มพร้อม Unicode character (u01CF)

วิธีใช้ Unicode และ Special Characters ใน Tkinter