954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

bug in tkMessageBox

I happened to see (and isolate) the following problem and have 2 questions:
1) tkMessageBox is used extensively in my code. How do I make my code work without a significant re-write?
2) how do I tell the wonderful tkinter developers that there is a problem?

The problem is seen when running python 2.6.2 on Ubuntu 904. Interestingly the problem is not happening when using python 2.5.4 on WinXP.

The problem manifests as follows:

>>> import tkMessageBox
>>> tkMessageBox.askyesno() #user clicks "yes"
True
>>> import tkFileDialog
>>> tkFileDialog.askopenfilename() #user can do whatver - e.g. click "cancel"
''
>>> tkMessageBox.askyesno() #user clicks "yes"
False
>>>

digging into the source I tried this:

>>> import tkMessageBox
>>> res=tkMessageBox._show(_type="yesno") #user clicks "yes"
>>> res
u'yes'
>>> type(res)

>>> import tkFileDialog
>>> tkFileDialog.askopenfilename() #user clicks "cancel"
''
>>> res=tkMessageBox._show(_type="yesno") #user clicks "yes"
>>> res

>>> print res
yes
>>> type(res)

>>>

Note that Python 2.5.4 on WinXP continues to return a string from tkMessageBox._show

The tkMessageBox.askyesno code executes the following, which fails when res is of type '_tkinter.Tcl_Obj':

From "/usr/lib/python2.6/lib-tk/tkMessageBox.py", line 74:

if isinstance(res, bool):
        if res: return YES
        return NO
    return res
no_spam_for_dan
Newbie Poster
2 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

I happened to see (and isolate) the following problem and have 2 questions: 1) tkMessageBox is used extensively in my code. How do I make my code work without a significant re-write? 2) how do I tell the wonderful tkinter developers that there is a problem?

The problem is seen when running python 2.6.2 on Ubuntu 904. Interestingly the problem is not happening when using python 2.5.4 on WinXP.

The problem manifests as follows:

>>> import tkMessageBox >>> tkMessageBox.askyesno() #user clicks "yes" True >>> import tkFileDialog >>> tkFileDialog.askopenfilename() #user can do whatver - e.g. click "cancel" '' >>> tkMessageBox.askyesno() #user clicks "yes" False >>>

digging into the source I tried this:

>>> import tkMessageBox >>> res=tkMessageBox._show(_type="yesno") #user clicks "yes" >>> res u'yes' >>> type(res) >>> import tkFileDialog >>> tkFileDialog.askopenfilename() #user clicks "cancel" '' >>> res=tkMessageBox._show(_type="yesno") #user clicks "yes" >>> res >>> print res yes >>> type(res) >>>

Note that Python 2.5.4 on WinXP continues to return a string from tkMessageBox._show

The tkMessageBox.askyesno code executes the following, which fails when res is of type '_tkinter.Tcl_Obj':

From "/usr/lib/python2.6/lib-tk/tkMessageBox.py", line 74:

if isinstance(res, bool):
        if res: return YES
        return NO
    return res

I've encountered the same problem and filed a bug report with Debian.

Hopefully the tkinter module will be fixed in the next minor update.

harishankar
Junior Poster
104 posts since Dec 2004
Reputation Points: 13
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You