[Tkinter-discuss] Crash when changing fonts

Russell E. Owen rowen at uw.edu
Thu Oct 24 21:42:02 CEST 2013


(approximate copy of message posted to tcl-mac)

I distribute a Mac application based on Tkinter that crashes when a user 
updates certain preferences that use the option database, including font 
size and some colors. It works OK with Tcl/Tk 8.5.11, but crashes using 
8.5.12, 8.5.12.1, 8.5.13 and 8.1.14.

I was finally able to come up with a simple test case in tcl (appended). 
I opened a ticket at the Tk bug reporter, but I figured I'd also post 
here, just to spread the word.

If anyone can think of a workaround (other than sticking with 8.5.11, 
which is what I've done so far, but it doesn't work with Mavericks) I'd 
really appreciate it. So far nothing I've tried works (except not adding 
entries to the "apple" menu, which would make the Mac version much less 
Mac-like, or never touching the option database, which removes a useful 
feature).

-- Russell

# tcl menu crash; to crash run the code and push the button
menu .parentMenu
menu .parentMenu.apple -tearoff 0
# the following line is optional, but shows the menu is created
.parentMenu.apple add command -label "Something"
.parentMenu add cascade -label Wish -menu .parentMenu.apple

font create testFont
option add "*Button.font" testFont

button .btn -text "Change Font" -command { font configure testFont -size 
20 }
pack .btn

. configure -menu .parentMenu


In Tkinter this reads as:

import Tkinter
import tkFont

root = Tkinter.Tk()

parentMenu = Tkinter.Menu(root)
appleMenu = Tkinter.Menu(parentMenu, name="apple", tearoff=0)
appleMenu.add_command(label="Something") # may be omitted
parentMenu.add_cascade(label="Python", menu=appleMenu)

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