Greek letters in a GUI - PYTHON

2019-07-21 09:07发布

I don't know how to write Greek letters in a GUI. I am working on a Physics program and I need to show units on the GUI.

Do I have to download any extra libraries? Is there a module I have to use? What is the easiest way to write the letters in the GUI?

I read a lot about UTF8 but didn't figure out how to use it.

I am using Tkinter for the GUI

I am using Python 2.6.6

Thanks

3条回答
霸刀☆藐视天下
2楼-- · 2019-07-21 09:38

Unicode includes definitions for both the Greek alphabet and several mathematical symbols. If you are using any form of Unicode in your environment, it should be simple:

>>> from Tkinter import *
>>> root = Tk()
>>> w = Label(root, text=u"Hello, \u03bc-world!")
>>> w.pack()
>>> root.mainloop()

This will print "Hello, μ-world!" in a Tkinter window.

查看更多
欢心
3楼-- · 2019-07-21 09:50
>>> print( u'\u03a9' )
Ω

Works for me.

What specific problem are you having?

查看更多
相关推荐>>
4楼-- · 2019-07-21 09:54

IDLE uses Tkinter, Greek letters seem to work fine in there for me

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************

IDLE 2.6.5      
>>> print "Ω ω"
Ω ω
>>> 

If you wish to use unicode literally in your source, you should include a line like this

# -*- coding: utf-8 -*-

At the top of each file

查看更多
登录 后发表回答