1

I am writing a program using Python 2.7 and Tkinter, and at one point I need to display variable symbols on my GUI. I've decided to use the Label object, but I need to display symbols such as alpha, beta, ohm, and pi. I don't know how to type them out, let alone make them appear in python. Here's an example of my code:

pilabeltext = StringVar()
pilabeltext.set("This is where I want the Pi symbol")
pilabel = Label(app,text=pilabeltext)
pilabel.pack()

I'd also like to be able to let characters in strings have subscripts and superscripts, so if I wanted to write alpha subscript 1 and alpha subscript 2, or alpha squared, how could I do that?

Thanks a bunch!

1
  • AFAIK, you can't use subscripts and superscripts in a Tkinter Label, but can work around this using a Text widget and use the tag option offset. Commented Aug 14, 2012 at 13:29

1 Answer 1

7

Ensure your script is UTF-8 encoded, then you should have no problems

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

from Tkinter import *

root = Tk()

w = Label(root, text="Hello, pi -> π !")
w.pack()

root.mainloop()

enter image description here

For using subscripts etc, have a look at this answer:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.