Some oddities in 2.3b1, esp. with Tkinter
"Martin v. Löwis"
martin at v.loewis.de
Tue Apr 29 17:42:46 EDT 2003
Russell E. Owen wrote:
> 1) A filter to remove fonts with non-ascii names (used to filter out
> stuff that I could not display in a pop-up menu) broke.
> try:
> unicode(fontName, 'ascii', 'strict')
> return True
> except UnicodeError:
> return False
>
> Python 2.2 throws UnicodeError. Python 2.3b1 throws TypeError. The fix
> is trivial (e.g. "except (UnicodeError, TypeError)". The filter is
> probably not needed anymore anyway, since Tk 8.4.2 can apparently
> display menu items with non-ascii characters.
I don't understand. Why do you ever need to convert the *font name*
to a Unicode string, or why would Python ever fail to do so? Font
names are ASCII only, all the time, so you can't possibly ever get
an exception here.
> 2) Tk file events are no longer supported:
>
> RuntimeError: _tkinter.createfilehandler not supported for threaded Tcl
>
> This is painful since it's hard to see how to write a proper networking
> GUI with Tkinter without file events for reading data. Perhaps I can get
> them back again by disabling the new threaded tcl support.
Are you using Debian by any chance? Otherwise, you should not see
a threaded Tcl.
If your Tcl installation is threaded, you should use
tkapp.createfilehandler instead.
> 3) Tk returning things as objects is nice, but I had this break at least
> one thing of mine and it will break others (see 4 below):
>
> I was assuming that the values in the dictionary returned by
> tkFont.Font.config() were strings. Fortunately this was easy to fix. A
> bit disconcerting -- I wonder how many any other little pitfalls like
> this still buried in my code -- but well worth the cost of the change.
What is the nature of that change?
> Example:
> v = StringVar()
> v is a <Tkinter.StringVar instance at 0x2c98a0>
> l = Label(textvariable=v)
> x = l["textvariable"]
> x is reported as a <namespaceVarName object at 0x0168b048>
> but is a _tkinter.Tcl_Obj based on the following traceback:
> root.getvar(x)
> Traceback...
> TypeError: getvar() argument 1 must be string, not _tkinter.Tcl_Obj
Please submit a bug report. This is easy to fix (just invoke
str() of the Tcl_Obj)
> 5) Note that Tkinter's handling of font objects does not seem to have
> changed. I was hoping it would start returning font objects instead of
> strings, or offer some way to convert the string to a font object, but
> apparently not:
Does Tk have the notion of "font objects"?
Regards,
Martin
More information about the Python-list
mailing list