9 Nov 2003 moshez   » (Master)

sisob: You could, of course, compare to the Python version. This is for Gtk+ 1, but I gather that the interface for 2 is even cleaner (I just couldn't easily find a tutorial with an example I can hack). This example is straight from the tutorial, except hacked to do what your version does.

Some concessions to the Advogato/HTML limitations: I usually prefer to indent functions, even those with one statement. However, I wasn't sure how to get it to look right, so "def hello" is not idiomatic :( [but still works!].

Note how Python didn't make me define a class or even a top-level function. Of course, I could, and the earlier versions of this hack actually this have this. But I really want to make the GUI answer to <code>print "Hello World"</code> (which is a valid Python program that...well...).

import gtk

window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
button = gtk.GtkButton("Hello World")
def hello(*_): print "Hello world"
button.connect("clicked", hello, None)
window.add(button)
window.connect("destroy", lambda *_: gtk.mainquit())
window.show_all()
gtk.mainloop()

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!