On Sat, Nov 15, 2008 at 6:53 PM, Vasilis Vlachoudis <[EMAIL PROTECTED]> wrote: > Dear all, > > The tkMessageBox.askquestion as also several other methods e.g Text.search > have changed the return value with python 2.5 wrt to 2.4 > > Run the following test program (below) with python 2.4 answering yes on > askquestion dialogs and change directory in the askdirectory > you will get (python 2.4, Tk/Tcl 8.4 Tkinter $Revision 50704$) > ans1= yes <type 'str'> > ans2= yes <type 'str'> > > Run the same example with python 2.5 (Tk/Tcl 8.5 Tkinter $Revision: 50704 $) > ans1= yes <type 'unicode'> > ans2= yes <type '_tkinter.Tcl_Obj'> > > First the ans1 is unicode instead of str and the second one after the > askquestion is _tkinter.Tcl_Obj! >
When you get a _tkinter.Tcl_Obj it means _tkinter wasn't able to detect and convert a received tcl object to a python object. When this happens the best you can do is get the string representation of the object by doing str(ans2) and then convert the value yourself (if you want to convert it to something else different than a string). With Tcl/Tk 8.5 and the current _tkinter you will see this happening very often, as tcl/tk now shares objects as much as it can. _tkinter checks for some specific tcl types but since it may receive any kind of object, like a pixel object, or bytecode object which are part of tcl (which happens to contain the same representation, that is why they got shared) it ends up returning this generic Tcl_Obj. > Also with python 2.4 tk/tcl 8.5, the Text.search now returns the > _tkinter.Tcl_Obj instead of str regardless of opening the > tkFileDialog.askdirectory() > > Best Regards > Vasilis > > # -------------- test program ----------- > from Tkinter import * > import tkMessageBox > import tkFileDialog > root = Tk() > ans = tkMessageBox.askquestion("Yes/No","Answer YES") > print "ans1=",ans,type(ans) > d = tkFileDialog.askdirectory(title="Please change directory") > ans = tkMessageBox.askquestion("Yes/No","Answer YES") > print "ans2=",ans,type(ans) > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss