Tkinter- Building a message box

T

Tuvas

I've been trying to build a fairly simple message box in tkinter, that
when a button is pushed, will pop up a box, that has a line of text, an
entry widget, and a button, that when the button is pushed, will return
the value in the line of text. However, while I can read the value of
the button, I want to wait till the button is pushed to return the
value. Any ideas of how I could do this?
 
R

Ron Adam

Tuvas said:
I've been trying to build a fairly simple message box in tkinter, that
when a button is pushed, will pop up a box, that has a line of text, an
entry widget, and a button, that when the button is pushed, will return
the value in the line of text. However, while I can read the value of
the button, I want to wait till the button is pushed to return the
value. Any ideas of how I could do this?

The way I do it is to set self.result in the dialog to the return value
just before closing and exiting.

And then instead of openiug the dialog directly I use a function to pass
and sometimes modify the values to the dialog and then return the
dialog.result value after it's closed.

Something like...

def domydialog(*args, **kwds):
#
# Check and modify args or kwds here if needed.
#
mydialog(*args, **kwds)
return mydialog.result

Cheers,
Ron
 
T

Tuvas

Do you have any info on dialogs? I've been trying to find some, without
alot of success...
 
T

Tuvas

Thanks alot, that helped TONS! Just had to modify it slightly, but,
well, it works great now. Thanks!
 
R

Ron Adam

Tuvas said:
Do you have any info on dialogs? I've been trying to find some, without
alot of success...

Be sure and look at the examples in python24/lib/lib-tk. The Dialog.py
file there does pretty much what you want.

In the dialog caller example I gave, it should have been ...

def domydialog(*args, **kwds):
#
# check or change args or kwds
#
d = mydialog(*args, **kwds)
return d.result

I left out the returned object name 'd'. Which is needed to get the
result from the dialog instance.

Cheers,
Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top