[Tkinter-discuss] Python 3.4.0 alpha 2 available
Russell E. Owen
rowen at uw.edu
Wed Sep 25 20:48:31 CEST 2013
In article <5242E9CB.3060508 at codebykevin.com>,
Kevin Walzer <kw at codebykevin.com> wrote:
> Hi Russell,
>
> On 9/24/13 8:23 PM, Russell E. Owen wrote:
> > Well, naturally the prime purpose is to demonstrate the crash. However,
> > if you use 8.5.11 or if you comment out the menu-related stuff then you
> > also will see the button text get larger. I only use the label to access
> > the option database.
>
> After a bit more digging, I think the bug here is another instance of
> http://bugs.python.org/issue15853, which caused IDLE to crash. In that
> case I submitted a patch that worked around the bug by changing how a
> font was configured in a certain context; see
> http://hg.python.org/cpython/rev/d089b8fb0f56 for the specifics.
>
> What suggests to me that this bug is similar, or even the same, is that
> changing your sample code from configuring the font object directly to
> specifically configuring the font on the button avoids the crash, cf:
>
> btn = Tkinter.Button(root, text="Change Font", command= lambda:
> btn.configure(font='-size 14'))
>
> Note the difference between font.configure(size=14) and
> btn.configure(font='-size 14'). In the patch we worked out for IDLE, the
> mechanism of the fix was the same, but the expected behavior of the code
> did not change: the font in the button gets bigger.
>
> The reason I focused on a workaround at the Python script level rather
> than a fix in Tk was partly because I couldn't reproduce the crash in
> Tcl itself, even by creating and configuring fonts rather than font
> attributes in a specific widget. That makes fixing the bug in Tk rather
> hard. It's possible that the bug is caused by some combination of
> triggers in Tk-Cocoa's fragile event loop that Python exposes more
> readily than Tcl code.
>
> The upshot of all of this is that I think it would be more productive to
> tweak application-level code to work around the bug--it's not likely
> that any fix for Tk-Cocoa's event loop issues is coming any time soon. I
> realize that may not be the answer you were looking for, and I'm sorry
> about that. But given the problems still remaining with Tk-Cocoa's event
> loop, I actually recommend script-level workarounds as a best practice;
> I do that in my own apps and have not run into a crash in a long time.
Ouch. I'm sure you are right that working around the bug is more
practical than waiting for a fix. Those event loop problems sound nearly
impossible to resolve.
The issue in this case is that I have hundreds of widgets to update. In
the real application a preferences panel is used to set font sizes for
various two classes of widgets. It sounds quite messy to have to set
those manually instead of using the option database.
It's not just fonts, either. I also have a few color preferences
(primarily to support color-blind users) and changing those color
preferences also crashes the application.
I don't know a practical way to find and configure all the correct
widgets.
-- Russell
P.S. I tried two stupid tricks. I didn't expect either to work, and
indeed they did not:
- use root.after to fire the font change later (in the very unlikely
hope that this would work around an event loop issue)
- use root.tk.call(...) to change the font size (of course this didn't
help; surely Tkinter is doing exactly the same thing)
P.P.S. here is slightly more minimal code. I got rid of the label widget
because root works just as well. As far as I can tell the rest is all
required.
import Tkinter
import tkFont
root = Tkinter.Tk()
parentMenu = Tkinter.Menu(root)
mnu = Tkinter.Menu(parentMenu, name="apple", tearoff=0)
parentMenu.add_cascade(label = "TUI", menu = mnu)
font = tkFont.Font()
root.option_add("*Button.font", font)
def changeFont():
font.configure(size=20)
btn = Tkinter.Button(root, text="Change Font", command=changeFont)
btn.pack()
root["menu"] = parentMenu
root.mainloop()
More information about the Tkinter-discuss
mailing list