I am searching for a simple dialog with a text entry widget asking the user for some input. The dialog should be easy to run (like the gtk.MessageDialog
variants) and as flexible.
There are of course some examples but they are either not flexible enough or too complicated to construct for my taste.
I hate re-inventing the wheel... or a dialog.
Based on an example I found (thanks Ardoris!), I came up with a dialog subclass... hope it helps someone out there!
The
run()
method returns either the text entered in the entry box if the user presses<Enter>
or clicks Ok. IfCancel
is clicked or<Esc>
pressed, therun()
method returnsNone
.Except for that, the dialog should behave as any other
gtk.MessageDialog
instance.Maybe that is not very general as it assumes you will always have Ok as an option, but that is what I need in 99% of my use cases anyway.
Here's the function I wrote, based on the previous answers here. It's a function instead of a class, which means you can use it in one line.
There isn't one available in GTK+. You've got two options:
Something along the lines of:
Though it does probably need more refinement to get the Entry to display nicely.