Newbie : Greek letters

O

Oh Kyu Yoon

Is there an easy way to include greek letter symbols in TextCtrl of
wxPython?

--
 
A

asdf sdf

Oh said:
Is there an easy way to include greek letter symbols in TextCtrl of
wxPython?


this is only a idea. no experience with it myself. Try using SetFont
to get Symbol font. Symbol font is available on WinPCs. Couldn't say
about any other platforms though.

Just tried it and it works on my Win2000 machine in PyCrust.

frame = wx.Frame(None, -1, 'title')
tc = wx.TextCtrl(frame, -1, 'D')
tc.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, face='SYMBOL'))
frame.Show(True)

A window popped up showing a Delta.

Then in PyCrust with the window still showing, I did

tc.SetLabel('G')

and the frame updated to show a Gamma.

Man, I have hardly any gui experience, not to mention hardly any python
experience, and I just started wxPython.

Bottom line: wxPython is _easy_. It's the lack of newbdoc that is the
problem.

Epsilon looks pretty much the same as E, Rho looks like P. Chi (X) is
wierd looking. Printing the rest of the alphabet is left as an exercise
for the reader.
 
A

asdf sdf

You reminded me that I would find this handy myself so I set up a
program to display greek letters. Pay no attention to the sizer
handling. Working on that.

sorry if the mailer munges the linewrapping. shouldn't be a biggie in
a script this small.

good luck.

#
# greek.py
#

import wx
import string

class Greek(wx.Frame):
''' greek alphabet '''

alphabet = string.ascii_letters

def __init__ (self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)

# wx.Font(points, family, style, weight, face='')
romanfont = wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
greekfont = wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL,
face='SYMBOL')

gs = wx.GridSizer(-1, 10, 5, 5)

roman = []
greek = []

textstyle = wx.ALIGN_CENTER|wx.ST_NO_AUTORESIZE
cellstyle = wx.EXPAND

for x in range(len(Greek.alphabet)):
letter = Greek.alphabet[x]

roman.append(wx.StaticText(self, -1, letter
,wx.Point(-1,-1), wx.Size(-1,-1), textstyle))
roman[x].SetFont(romanfont)
roman[x].SetBackgroundColour('Yellow')

greek.append(wx.StaticText(self, -1, letter
,wx.Point(-1,-1), wx.Size(-1,-1), textstyle))
greek[x].SetFont(greekfont)
greek[x].SetBackgroundColour('White')

gs.Add(roman[x], 1, cellstyle, 10)
gs.Add(greek[x], 1, cellstyle, 10)

# layout sizers
self.SetSizer(gs)
self.SetAutoLayout(1)
gs.Fit(self)

self.Show(True)

app = wx.PySimpleApp()
frame = Greek(None, -1, 'Greek Alphabet')

app.MainLoop()

# -------------------------------------
# greek.py - end of file
# -------------------------------------
 
C

Christopher Culver

this is only a idea. no experience with it myself. Try using SetFont
to get Symbol font. Symbol font is available on WinPCs. Couldn't say
about any other platforms though.

That is a bad idea. Not only does it break cross-platform compatibility
(the goal of wxWindows) by using a proprietary font, it totally ignores
Python's excellent Unicode support. Greek has it's own block in Unicode,
you just have to create the characters from there. Using special fonts to
overcome character sets is sooooo 1998.

Christopher Culver
 
A

asdf sdf

Christopher said:
That is a bad idea. Not only does it break cross-platform compatibility
(the goal of wxWindows) by using a proprietary font, it totally ignores
Python's excellent Unicode support. Greek has it's own block in Unicode,
you just have to create the characters from there. Using special fonts to
overcome character sets is sooooo 1998.

Christopher Culver


well, i'm edified. how about a code example? isn't there some issue
about whether a given wxpython build has unicode support? how do you
tell? how do you add it if you don't have it?

if i may paraphrase the OP's question... "can i do greek letters in
python?".

if i may paraphrase your helpful response..."yes".

cool 'tude though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top