Tk Dialog Boxes

Paul Simmonds psimmo60 at hotmail.com
Tue Dec 3 04:48:17 EST 2002


<problem description snipped>
>
>The problem I have is that I want to return a value back to the calling
>program.
>

Hi,

like Jorgen, I use the tkSimpleDialog Dialog class. It provides a very 
useful generic Toplevel window that has all the modality and focus-switching 
already available.

The way this class returns a value is through its result attribute. The 
destroy method will delete the window from the screen, but the attributes 
can still be used as long as there are references to them in the code. The 
Dialog class initialises the result attribute to None, then the apply() 
method can be overidden to set any value of result that you need.

<simple example of usage>
>>>import tkSimpleDialog
>>>class MyDialog(tkSimpleDialog.Dialog):
...     def __init__(self,parent,title=None):
...         tkSimpleDialog.Dialog.__init__(self,parent,title)
...     def apply(self):
...         self.result="Ok"
...
>>>print MyDialog(parent=None).result # Clicking OK
Ok
>>>print MyDialog(parent=None).result # Clicking Cancel
None
<code ends>

HTH,
Paul

>TIA, Newt
>
>
>--
>http://mail.python.org/mailman/listinfo/python-list


_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus





More information about the Python-list mailing list