Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to use Unicode and Special Characters in Tkinter?
Sometimes we need to add Unicode and special characters in our Tkinter application. We can add Unicode characters in our labels or widgets by concatenating the signature as u'\u<Unicode of Character>'. You can find the list of all Unicode characters from here.
Basic Unicode Character Example
In this example, we will add a Unicode character in the button widget ?
# Import the required Libraries
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
win.geometry("700x200")
# Create a button with Unicode character
Button(win, text='Click' + u'\u01CF', font=('Poppins bold', 10)).pack(pady=20)
# Keep running the window or frame
win.mainloop()
Running the above code will create a button with a Unicode character (u01CF).
Common Unicode Characters in Tkinter
Here are some commonly used Unicode characters in GUI applications ?
from tkinter import *
win = Tk()
win.geometry("400x300")
win.title("Unicode Characters Demo")
# Various Unicode symbols
Label(win, text="Arrow: " + u'\u2192', font=('Arial', 12)).pack(pady=5)
Label(win, text="Heart: " + u'\u2764', font=('Arial', 12)).pack(pady=5)
Label(win, text="Star: " + u'\u2605', font=('Arial', 12)).pack(pady=5)
Label(win, text="Music: " + u'\u266B', font=('Arial', 12)).pack(pady=5)
Label(win, text="Check: " + u'\u2713', font=('Arial', 12)).pack(pady=5)
win.mainloop()
Using Raw Unicode Strings
You can also use raw Unicode strings for better readability ?
from tkinter import *
win = Tk()
win.geometry("300x150")
# Using raw Unicode string
copyright_symbol = '\u00A9'
trademark_symbol = '\u2122'
Label(win, text=f"Copyright {copyright_symbol} 2024", font=('Arial', 14)).pack(pady=10)
Label(win, text=f"TutorialsPoint{trademark_symbol}", font=('Arial', 14)).pack(pady=10)
win.mainloop()
Common Unicode Categories
| Category | Unicode | Character | Description |
|---|---|---|---|
| Arrows | \u2192 | ? | Right arrow |
| Symbols | \u2764 | ? | Red heart |
| Math | \u221E | ? | Infinity |
| Currency | \u00A3 | £ | Pound sign |
Conclusion
Unicode characters in Tkinter are added using the u'\u<code>' format. This allows you to display special symbols, arrows, and international characters in your GUI applications for better user experience.
