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)
<type 'unicode'>
>>> import tkFileDialog
>>> tkFileDialog.askopenfilename() #user clicks "cancel"
''
>>> res=tkMessageBox._show(_type="yesno") #user clicks "yes"
>>> res
<booleanString object at 0xa103790>
>>> print res
yes
>>> type(res)
<type '_tkinter.Tcl_Obj'>
>>>

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 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)
<type 'unicode'>
>>> import tkFileDialog
>>> tkFileDialog.askopenfilename() #user clicks "cancel"
''
>>> res=tkMessageBox._show(_type="yesno") #user clicks "yes"
>>> res
<booleanString object at 0xa103790>
>>> print res
yes
>>> type(res)
<type '_tkinter.Tcl_Obj'>
>>>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.