[Tkinter-discuss] Syntactic problems

Kevin Walzer kw at codebykevin.com
Fri Dec 2 16:45:04 CET 2011

On 12/2/11 7:09 AM, Francisco Gracia wrote:

> Â
> Some of the names of the font families returned by the operating system
> (be it Windows or Linux) are composed of two or more words (like *Times
> New Roman CE*). Now these multiword arguments are not easily accepted by
> *Tcl/Tk*, especially if they are referenced by some variable, so that
> for instance tags cannot be reconfigured this way in order to apply such
> fonts; or the size of sentences using them cannot be measured, two
> operations that are essential for the procedure.

Multi-named fonts can be tricky.

> Â
> I have learned that this is a real and inherent difficulty with *Tcl*
> (Harrison and McLennan, *Effective Tcl/Tk programming*: 34, 66); this is
> why the original code uses such a strange syntax like
> Â
> Â Â Â  .t tag configure f[incr count] -font [list $family 10]
> Â
> The function *list* of *Tcl* seems to be mainly dedicated to solve this
> odd problem with the dereferencing of multiword contents of variables
> (*family* in this case, which holds the name of the font). But
> apparently this does not work when *Tcl/Tk* are finally moved by
> *Tkinter* during the execution of the script or at least I have been
> unable to find a way to make it work in due form.

I'm not quite clear on what problem you are experiencing here, as there 
are no code snippets or Python errors outlined.

Are you just trying to understand the underlying Tcl idioms?

In Tcl, the [list $family 10] converts the multi-named font into a 
single string that can be parsed by the font code. Tcl's [list] idiom is 
very handy for things like this.

I'm not sure about how the Tkinter module interacts with Tcl at that low 
level, but this Python code has always worked for me in displaying and 
selecting a font from a listbox:


         for item in self.fonts:
             self.fontlist.insert(END, item)

         newfontlist = list(self.fontlist.get(0, END))

         if self.fontname in newfontlist:
             i = newfontlist.index(self.fontname)

(This code is partly based on code in IDLE. The code in idleib is a bit 
wooly, but snippets of it are quite useful for Tkinter samples.)

Hope this helps,

> Â
> Which does not mean much, as I am not a programmer or, at most, I am a
> very unseasoned one. Can somebody who has had the same problem and
> solved it succesfully from *Tkinter* offer me (and perhaps us) his
> insight and describe the essentials of how to do it?
> Â
> Many thanks in advance!
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

Kevin Walzer
Code by Kevin

More information about the Tkinter-discuss mailing list