📜  如何在 Tkinter 中使用 Unicode 和特殊字符?

📅  最后修改于: 2022-05-13 01:55:25.418000             🧑  作者: Mango

如何在 Tkinter 中使用 Unicode 和特殊字符?

先决条件: Tkinter

Python为开发 GUI(图形用户界面)提供了多种选择。在所有 GUI 方法中,Tkinter 是最常用的方法。它是Python附带的 Tk GUI 工具包的标准Python接口。 Python with Tkinter 是创建 GUI 应用程序的最快、最简单的方法。

在本文中,我们将学习如何在 Tkinter 中使用 Unicode 和特殊字符。

方法:

  • 制作一个包含 Unicode 值的列表。
  • 遍历所有 Unicode 值,然后传入 Label 文本
  • 我们将使用“u 前缀”来显示 Unicode 值。

例子:

for "Not sign" unicode value is "00AC"

Input
u'\u00AC'

Output
¬

以下是实现:-

Python3
# Import Tkinter
from tkinter import *
 
# Create Object
root = Tk()
 
# Set geometry
root.geometry("100x200")
 
# Unicodes values
unicodes_values = [
'\u00A1',
'\u00A2',
'\u00A3',
'\u00A4',
'\u00A5',
'\u00A6',
'\u00A7'
]
 
# Iterate through all unicode values
for unicodes_value in unicodes_values:
    Label(root, text = u'{unicodes_value}'.format(
      unicodes_value = unicodes_value)).pack()
 
# Execute Tkinter
root.mainloop()



输出: