PDA

View Full Version : gtk.main() does nothing?



Martje_001
August 31st, 2008, 07:40 PM
Hello,
I've build a glade file and a python one, but when I run the python file, nothing happens!

pyhelloworld.glade:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sun Aug 31 20:28:23 2008 -->
<glade-interface>
<widget class="GtkWindow" id="window1">
<signal name="destroy" handler="on_window1_destroy"/>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">Hello world!</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
</widget>
</child>
</widget>
</glade-interface>

PyHelloWorld.py:

#!/usr/bin/python
import gtk
import gtk.glade
import gnome.ui

def DestroyFunction(obj):
gtk.main_quit()

widgetTree = gtk.glade.XML("pyhelloworld.glade")

dic = { "on_window1_destroy" : DestroyFunction }

widgetTree.signal_autoconnect (dic)

gtk.main()

Anyone, please?

kknd
August 31st, 2008, 08:21 PM
You need to get a ref to the window, and show it (window.showAll() to show the children too)

Martje_001
August 31st, 2008, 08:39 PM
I'm a complete newbie. Could you tell me how to do this?

kknd
September 1st, 2008, 01:17 AM
In pseudocode:

Glade xml = Glade.load("file")
Window w = xml:getWidget("yourwidgetname")
w:showAll()

Martje_001
September 1st, 2008, 10:57 AM
Thank you, but the problem was:

<property name="visible">True</property>

kknd
September 1st, 2008, 11:44 PM
Thank you, but the problem was:

<property name="visible">True</property>

Nice. The show method would set the property visible to TRUE too =).