unexplained behavior of tkMessageBox.askyesno

Peter Kleiweg in.aqua.scribis at nl.invalid
Tue Sep 7 17:25:18 EDT 2004


Peter Kleiweg schreef:

>
> I have a program with these fragments:
>
>
>
> from Tkinter import *
> import tkFileDialog
> import tkMessageBox
>
> def openProject():
>     filepath = tkFileDialog.askopenfilename(filetypes=(("project files","*.ini"), ("all","*")))
>     if filepath:
>         loadProject(filepath)
>
> def makeClean():
>     if tkMessageBox.askyesno('Make clean', 'Remove all files created by Make?'):
>         print 'yes'
>         # more code

The file tkMessageBox.py that comes with Python has this:

def askyesno(title=None, message=None, **options):
    "Ask a question; return true if the answer is yes"
    s = _show(title, message, QUESTION, YESNO, **options)
    return s == YES


So instead of calling askyesno, I used this:

def makeClean():
    r =  tkMessageBox._show('Make clean', 'Remove all files created by Make?', 'question', 'yesno')
    print type(r), r

Call makeClean(), click no, result: <type 'str'> no
Call makeClean(), click yes, result: <type 'str'> yes
Call openProject(), click cancel
Call makeClean(), click no, result: <type 'str'> no
Call makeClean(), click yes, result: <type 'bool'> True

Now, how did that happen?

-- 
Peter Kleiweg  L:NL,af,da,de,en,ia,nds,no,sv,(fr,it)  S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html




More information about the Python-list mailing list