Difference between revisions of "PyGTK"
(→Control and Display) |
|||
| Line 1: | Line 1: | ||
PyGTK is loads better than TKinter. There are far more events to work with which let you make a more responsive, convenient, and concise interface.<br> | PyGTK is loads better than TKinter. There are far more events to work with which let you make a more responsive, convenient, and concise interface.<br> | ||
I am using Glade to create the gui. pygtk is well documented; glade is not.<br> | I am using Glade to create the gui. pygtk is well documented; glade is not.<br> | ||
| − | For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade. | + | For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade.<br> |
| + | holy crap, there's gtk 3, it's buried beneath a lot of gtk 2 documentation on the internet. But it's so much better. | ||
| + | <br>But... it seems to require python 3, which I'd like to use but there are some issues with that.<br> | ||
| + | Fortunately, the only thing I know of that doesn't work are comboboxtext widgets, which are convenient but don't add anything new.<br> | ||
| + | Also, apparently, gtk 3 is not so widespread, particularly on Windows, which will be the main platform for the program I'm making. | ||
==Loading a glade file, hooking up event handlers, and displaying a window== | ==Loading a glade file, hooking up event handlers, and displaying a window== | ||
<source lang="python">#Load the file | <source lang="python">#Load the file | ||
| Line 58: | Line 62: | ||
***Set the Text property to the column you want displayed from the ListStore | ***Set the Text property to the column you want displayed from the ListStore | ||
| <source lang="python">cb = builder.get_object('comboboxname') | | <source lang="python">cb = builder.get_object('comboboxname') | ||
| − | + | cb.get_active_text()</source> | |
|- | |- | ||
| Treeview | | Treeview | ||
Latest revision as of 03:12, 15 June 2013
PyGTK is loads better than TKinter. There are far more events to work with which let you make a more responsive, convenient, and concise interface.
I am using Glade to create the gui. pygtk is well documented; glade is not.
For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade.
holy crap, there's gtk 3, it's buried beneath a lot of gtk 2 documentation on the internet. But it's so much better.
But... it seems to require python 3, which I'd like to use but there are some issues with that.
Fortunately, the only thing I know of that doesn't work are comboboxtext widgets, which are convenient but don't add anything new.
Also, apparently, gtk 3 is not so widespread, particularly on Windows, which will be the main platform for the program I'm making.
Contents
Loading a glade file, hooking up event handlers, and displaying a window
#Load the file
import gtk
gladefile = 'app.glade'
builder = gtk.Builder()
builder.add_from_file(gladefile)
#Connect callback handlers
handlers = {}
handlers['button_clicked_cb'] = buttonclickedfunction
builder.connect_signals(handlers)
#Display the window
window = builder.get_object('mainwindow')
window.show_all()But first you have to create the glade file. Create a window and divide it with boxes and then put widgets in each panel and widgets within those widgets as needed.
Actions
What are actions for? Do they let me configure a button to launch a file dialog?
Toplevels
| widget | glade | python |
|---|---|---|
| Window | Make an empty window | window = builder.get_object('windowname')
window.show_all() |
| FileChooserDialog |
|
??? |
Control and Display
| widget | glade | python |
|---|---|---|
| ComboBox |
|
cb = builder.get_object('comboboxname')
cb.get_active_text() |
| Treeview
(ListStore) |
|