View Full Version : Simple Python GUI
Levo
July 1st, 2009, 10:39 AM
I want to make a very simple Python GTK GUI Application. I need only one window, with three buttons (Yes, No, Cancel). And an about dialog (if possible). I don't know much about python. I hope you can help me!
mhh91
July 1st, 2009, 10:52 AM
look for an IDE that supports PyGTK
Nevon
July 1st, 2009, 11:06 AM
For something that simple, couldn't you use Zenity? I haven't tried it with Python, but I don't see why it wouldn't work.
Levo
July 1st, 2009, 11:08 AM
For something that simple, couldn't you use Zenity? I haven't tried it with Python, but I don't see why it wouldn't work.
Yes I've already tried zenity. But there is no YES/NO/Cancel dialog.
Levo
July 1st, 2009, 11:19 AM
look for an IDE that supports PyGTK
Can you suggest me one? Or maybe can you help me how to make a basic window?
monraaf
July 1st, 2009, 11:33 AM
Here you go:
#!/usr/bin/env python
import gtk
dialog = gtk.Dialog("Are you sure?", None, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_NO, gtk.RESPONSE_NO,
gtk.STOCK_YES, gtk.RESPONSE_YES))
response = dialog.run()
dialog.destroy()
while gtk.events_pending():
gtk.main_iteration(False)
if response == gtk.RESPONSE_YES:
print 'yes'
elif response == gtk.RESPONSE_NO:
print 'no'
Levo
July 1st, 2009, 11:44 AM
Here you go:
#!/usr/bin/env python
import gtk
dialog = gtk.Dialog("Are you sure?", None, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_NO, gtk.RESPONSE_NO,
gtk.STOCK_YES, gtk.RESPONSE_YES))
response = dialog.run()
dialog.destroy()
while gtk.events_pending():
gtk.main_iteration(False)
if response == gtk.RESPONSE_YES:
print 'yes'
elif response == gtk.RESPONSE_NO:
print 'no'
Thank you very much for this!
Now two more questions about your nice script: How can I add a text? And how can I change buttons' names?
monraaf
July 1st, 2009, 11:55 AM
Well, I'm not going to do all your work for you. For the label you can insert the following code before the dialog.run().
label = gtk.Label("Hello World")
label.show()
dialog.get_content_area().add(label)
For the rest, you can help yourself out here:
http://www.pygtk.org/docs/pygtk/index.html
Levo
July 1st, 2009, 11:57 AM
Well, I'm not going to do all your work for you. For the label you can insert the following code before the dialog.run().
label = gtk.Label("Hello World")
label.show()
dialog.get_content_area().add(label)
For the rest, you can help yourself out here:
http://www.pygtk.org/docs/pygtk/index.html
Well, I said I need help, either a tutorial, or a sample script.
master_kernel
July 1st, 2009, 09:49 PM
look for an IDE that supports PyGTK
I don't think there are any, or if there are, they probably aren't good.
Tutorial:
http://www.pygtk.org/pygtk2tutorial/index.html
Levo
July 2nd, 2009, 03:49 PM
I want to set a variable:
DIR = gtk.FileChooserDialog(title="Please select an file",
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
FILE = DIR.get_filenames()
DIR.run()
How can I now use the variables I set? E.g. to print their values.
benj1
July 2nd, 2009, 03:59 PM
why don't you have a look at zenity, not python but dead easy, installed by default, check the man page, will save you learning gtk just to do a simple box, unless of course you want to
ee_guy
July 2nd, 2009, 04:01 PM
I tried an IDE for pygtk and it was pretty bad. I ended up using boa-constructor with wxpython for a project that I did. I was pretty new to python at the time and I had not made GUIs so it really helped me out a lot. There are also some really good tutorials for boa-constructor.
Levo
July 2nd, 2009, 04:43 PM
why don't you have a look at zenity, not python but dead easy, installed by default, check the man page, will save you learning gtk just to do a simple box, unless of course you want to
I added more buttons to the dialog, so zenity doesn't fit. + I want to learn python/pygtk.
But I now need help with the variables.
bruce2000
July 2nd, 2009, 07:15 PM
I added more buttons to the dialog, so zenity doesn't fit. + I want to learn python/pygtk.
But I now need help with the variables.
This site has a good tutorial for building a gui with pygtk and glade:
http://www.micahcarrick.com/12-24-2007/gtk-glade-tutorial-part-1.html
There are more here if you're interested:
http://www.pygtk.org/articles.html
smartbei
July 2nd, 2009, 09:02 PM
I really think you should take the time to learn basic python before getting into GUI work. Make some console programs, take a look at the beginners challenges here at the forum, etc.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.