pygame is
Simple DirectMedia Layer is
Site Swing

Glyph - 2.0.0.a2

Chandler Armstrong (omnirizon)



glyph is a library for manipulating text and printing it to a pygame window.

so what? there are about a million pygame libraries to do that already.

glyph is different for a few reasons:

1) glyph provides a within string literal mini-language for text manipulation. you can use the mini-language to indicate what you want exactly where you want it, all right within the string literal.

2) glyph provides typesetting like functionality: positioning text, wrapping text, justifying text, scrolling text, switching font, text color, background color, even inserting images into text

3) glyph provides 'linked' text: text that returns a value whenever the mouse is hovering over it. this can be used to route the user around your program, or provide tooltips.

one simple object, the Glyph object, provides all this functionality. how? because Glyph interprets a mini-language, provided in string literals, that indicates how the Glyph object should treat text.


glyph mark-up language: glyph accepts special commands given through markup in the text. the language can be used to change font, size, color, background color, and denote text as 'linked'.

the commands given in the mark-up language are called 'environments'. all text inside of an environment is treated according to the environemnt type. for example, text can be italicized by starting an italics environment, and all text inside the environment will be blitted to the screen as italicized.

environments are started with a left curly bracket '{', and terminated with a right curly bracket '}'. the first text following the left curly bracket is the type of the environment. currently, the following types are available:

font - tells glyph that this font should be used in this environment
color - tells glyph that this color should be used in this environment
bkg - tells glyph that this background color should be used in this environment
link - tells glyph that this text is 'linked'

environments can be nested. when two environments of the same type are nested (e.g. two font environments), the most recent will take precedence.

immediately following the environment type are the arguments. the arguments specify what the environment will do to the text within it. arguments must be seperated with commas and terminated with a semi-colon. below are the environments and the arguments they expect:

font - file, size
file is the path to the directory containing the font file
size will be the size of the font

color - R, G, B
R, G, B are the red, green, blue values, respectively.

bkg R, G, B
R, G, B are the red, green, blue values, respectively.

link - linkname
linkname is the name of the link, and will serve as the key for all the rects associated with the link

below are some example environments:

glyph can {font fonts\\silkscreen_bold, 8;bold} text for you.
it can also {color (255, 0, 0);color} text for you.
it can even {font fonts\\silkscreen_bold, 8;nest these {color (255, 0, 0);features} for you}.

the environments and arguments can become cumbersome to type out. fortunately, glyph can store macros that will allow long rules to be abbreviated. to do this, simply add an entry to the glyph.Macro dictionary, with the key being the abbreviation, and the value being the environment type and environment:

glyph.Macro['b'] = ('font', Font(silkscreen_bold, 8))
glyph.Macro['red'] = ('color', (255, 0, 0))

with macros set, simply use the abbreviation at the start of environments rather than the name and argument list:

glyph can {b;bold} text for you.
it can also {red;color} text for you.
it can even {b;nest these {red;features} for you}.


Home Page:


click to view original size


Glyph - 2.6.5 - Dec 23, 2012
Glyph - 2.6.0b - Jul 6, 2012
Glyph - 2.5.4rc - Jul 27, 2011
Glyph - 2.5.3rc - Jul 9, 2011
Glyph - 2.5.2rc - Jun 25, 2011
Glyph - 2.5.1 - Mar 27, 2011
Glyph - 2.5.0 - Mar 2, 2011
Glyph - 2.4.0 - Dec 12, 2010
Glyph - 2.1.0b - Oct 5, 2010
Glyph - 2.0.0.a2 - Aug 1, 2010
Glyph - 2.0.0.a - Jul 18, 2010
Glyph - 1.2.0 - Jan 14, 2009
Glyph - 1.1.0 - Jan 10, 2009
Glyph - 1.0.0 - Jan 3, 2009 account Comments

If you wish to leave a comment with your account, please sign in first.

February 16, 2013 5:32am - seputarsoftware - nickname: (seputarsoftware)
great job guys
February 16, 2013 5:31am - seputarsoftware - nickname: (seputarsoftware) - 5/5
cool game
December 31, 2012 8:48am - seputarsoftware - nickname: (seputarsoftware) - 5/5
September 3, 2012 12:30pm - seputarsoftware - nickname: (seputarsoftware) - 5/5
March 3, 2011 12:04pm - Robert Leachman - nickname: (quazar)
Tried 2.5.0 and it's not working. Looking at this feedback page maybe we should take it to email? I just wrote to omnirizon at I am [email protected] let's figure this out?
March 1, 2011 3:57pm - Robert Leachman - nickname: (quazar)
I released Pythentene and Glyph is in the credits. Omnirizon I wonder if you could take a look and see how I did? I wonder if there's any improvements you might note. It occurred to me to not default at 640x480 but instead can test and use a higher resolution, but still would be nice to make the tiny screen look as good as possible. In any case, thanks!
February 2, 2011 11:30pm - Robert Leachman - nickname: (quazar)
Well there's more to the story; I moved the font directory as you said but then the demo wouldn't start at all, so I *copied* the font directory to both places. No luck, so added a statement `print env[1]` right before the crash... I see it emits "font\silkscreen_bold.ttf" which would probably work on Windows but not on Unix. I think it's a job for os.path.join though I see you use that in some places so... dunno, HTH
January 30, 2011 11:53am - Chandler Armstrong - nickname: (omnirizon)
ok I see the problem. the glyph demo needs the font folder inside the same directory as the file. I thought I had packaged it that way, but at any rate it was bad form. I'll change the demo code to get its current working directory and look for font files there.

to get the demo working for you now, simply put the font directory that came packaged with glyph back in the glyph directory.
January 29, 2011 11:43am - Robert Leachman - nickname: (quazar)
Thanks for the reply omnirizon! I didn't figure out the error below. Tried some bitmap font action but it didn't seem to help, marked it to revisit later as you say it doesn't look too bad.
January 24, 2011 12:22am - Chandler Armstrong - nickname: (omnirizon)
also, I've got some updates incoming that fix problems with glyph. namely, sometimes strings too long for the glyph rect would cause errors before reaching the point that glyph informs the user the error is that the string was too long. also, there was a bug that often caused unwanted behavior if the input text began with an environment. finally, i've worked with the editor to provide text wrapping for it and simplify the process of using the cursor.
January 24, 2011 12:18am - Chandler Armstrong - nickname: (omnirizon)
hey there. did you get the problems with the font filename sorted? I need to do something to provide some information as to the source of the problem in the input text to glyph.

that image you linked looks fine. unfortunately, non-bitmap fonts tend to look less than stellar with pygame; I suppose the pygame font library doesn't handle the sub-pixel anti-aliasing instructions in curve-based fonts very well. I always use bitmap fonts. Silkscreen is good and one of the few bitmaps fonts to offer normal, bold, and italics versions of the same font. Proggy, though, is probably my favorite. take care, most bitmap fonts only look good at one size.
January 16, 2011 7:57pm - Robert Leachman - nickname: (quazar)
Mr. Armstrong you've saved me a ton of time! But there's other work to do so can't show you the source code yet... would you mind looking at and tell me what I might have missed? The text layout is STELLAR but I wonder if it could render the font better? THANKS
January 16, 2011 7:55pm - Robert Leachman - nickname: (quazar)
I'm running 2.4 and the demo starts fine, the editor runs, but when I click to try to learn >here< to learn about this wonderous mini-language the demo crashes with:
File "", line 322, in <module>
File "", line 277, in start
glyph.input(PAGES[link], justify = 'justified')
File "/Users/rob/Downloads/glyphTest/glyph/glyph/", line 410, in input
interpreted_txt = interpret(txt) #
File "/Users/rob/Downloads/glyphTest/glyph/glyph/", line 321, in _interpret
envs.append(read_env(_txt_)) # append new environemt
File "/Users/rob/Downloads/glyphTest/glyph/glyph/", line 266, in __read_env
return ('font', Font(path, int(size))) # return new font
IOError: unable to read font filename
I'm running using Python 2.5 with this tree:
Also I've got something else on my mind... separate post.
December 20, 2010 10:22am - Chandler Armstrong - nickname: (omnirizon)
In the interest of repeatability, can you make sure the folder structure is like this:


make sure glyph is directly on your PYTHONPATH.

I cannot repeat your error, but I think it might be caused by you still having the glyph module inside a folder named 'glyph-2.4.0'. Also, make sure you include all the files in the module as I had packaged them, the __init__ file is responsible for naming the objects, so if you had replaced it the objects would not be available.
December 20, 2010 3:21am - Kilon Alios - nickname: (kilon)
Tried it, it reported this

Traceback (most recent call last):
File "C:\Users\XXX\Downloads\glyph-2.4.0\glyph\", line 3, in <module>
from glyph import Editor, Glyph, Macros
ImportError: cannot import name Editor
December 16, 2010 10:51am - Chandler Armstrong - nickname: (omnirizon)
yes, as I stated in the instructions above, _you_ must rename the folder to glyph. I don't have this packaged with an installer. The next release will provide an installer option; the practices of distribution are something I'm just now learning.
December 16, 2010 8:37am - Kilon Alios - nickname: (kilon) - 1/5
i tried to run it but it reports "no module named glyph" and fails to execute .
August 2, 2010 1:11am - Francesco Pasa - nickname: (frapa) - 5/5
Have you add background text color in the last release? It's very useful this library!!!
August 1, 2010 6:09am - Chandler Armstrong - nickname: (omnirizon)
request delivered! and then some.
July 22, 2010 8:28pm - Andy Hanson - nickname: (rhodiumgames)
It would be nice to have a resizing feature.
January 4, 2009 2:29pm - Chandler Armstrong - nickname: (omnirizon)
well everything should be working. i didn't include the scrolling view feature, but its easy enough to add to the program. you would simply need to add a variable that reset to zero every loop, and map a key, like PAGE_UP and PAGE_DOWN to change it to one or negative one (or a higher number for faster scrolling) for one loop, then add this variable to the scroller's output call.

you could do a similar thing for the pager object to see the page flipping feature, as long as you had some text that was more than could fit in the page height (by default, also the rect height).

actually, i think you could see page flipping on the current program in the editor. just type until you fill up the editor box, it should automatically flip to a new page and you can keep typing. backspace, deleting all characters off the new page, until the editor flips back to the old page. all your old text should still be there and your (invisible) cursor will be at the position of the most recent character.
January 4, 2009 7:47am - Luca Fabbri - nickname: (keul) - 4/5
However all this seems promising! I'm not sure of what of the features described are right now working (or may be that they aren't available through the example program?).
January 3, 2009 11:13pm - Chandler Armstrong - nickname: (omnirizon)
i noticed that too. it was kind of weird

i don't know html at all, and needed to use some to even be able to insert a description. your project was right there at the top and I just used your html source. so our descrip pages look a lot alike too :)

i've actually been working on/with this project since last summer. like you, i wrote it for a game i'm writing that needed lots of text processing. i didn't want to release until I had put the module through the angles by using it in actual design. I've finally done that now and am pretty happy with it, so decided to put it up.
January 3, 2009 10:18pm - Luca Fabbri - nickname: (keul)
D'oh! I think we released two very similar projects one some hours after the other, but for what I see you are more advanced :-)

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Feb 21, 2017

Jan 31, 2017

Jan 24, 2017

Jan 18, 2017

Jan 7, 2017

Dec 30, 2016

Dec 8, 2016

Nov 28, 2016

Nov 27, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)