My original program used input, like this:

n = input("Enter your favorite number: ")
# do stuff with number

Now, I have switched to a GTK GUI, but still want the accomplish the same thing. Now look at this very similar piece of code:

n = myWindow.getNumber()
# do stuff with number

Would it be possible to write a getNumber() method that only returns after the user presses a submit button in the window? (like the how the input function works) or is this my only option:

def callback(widget, event):
    n = myWindow.inputWidget.getValue()
    # do stuff with number

n = myWindow.getNumber(callback)

Update: I'm looking to do this without a gtk.Dialog, as I don't want a dialog popping up every time user input is required.


What you need is a modal dialog. I don't know GTK (or PyGTK) at all, but there appears to be an example in the documentation.

  • Thanks, but a modal dialog just prevents the user from interacting with any widgets outside of the dialog. – Sam Magura May 25 '11 at 18:24
  • 1
    @Sam: as far as I know, the run method of gtk.Dialog does block the program and only returns when it gets a response (no need for a callback). Subclassing gtk.Dialog may be what you need. – Jong Bor Lee May 25 '11 at 21:01

Your Answer

