1

i am trying to build a GUI using pygtk and glade on Windows. I am a noob at python GUI building so please excuse my noobness. I Looked up this tutorial and did exactly as it said. The only difference was that I am on Windows 7 Home Premium x64 .

I put a Label and a button in a window using glade as in the tutorial and then i got a libglade xml file. Then i typed the following code

import sys import pygtk import gtk import gtk.glade pygtk.require("2.0") class HellowWorldGTK: def __init__(self): #Set the Glade file self.gladefile = "Hello_World.glade" self.wTree = gtk.glade.XML(self.gladefile) #Get the Main Window, and connect the "destroy" event self.window = self.wTree.get_widget("MainWindow") if (self.window): self.window.connect("destroy", gtk.main_quit) if __name__ == "__main__": hwg = HellowWorldGTK() gtk.main() 

I put both the files in the same folder and then i run a python interpreter from the command line into the folder.Apparently The program runs but the thing is that i'm unable to get the interface all i get on the command line is that that the Program is running. I dont even get an error or something.Is it due to the fact that i'm on Windows?? I thought that GTK was cross-platform and the same code should run on windows as well as on Linux??

Also here is the .glade file generated by GLADE GUI designer

<?xml version="1.0" encoding="UTF-8"?> <glade-interface> <!-- interface-requires gtk+ 2.24 --> <!-- interface-naming-policy project-wide --> <widget class="GtkWindow" id="Hello world!"> <property name="can_focus">False</property> <property name="resizable">False</property> <child> <widget class="GtkVBox" id="vbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <widget class="GtkLabel" id="Click Here!"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">label</property> </widget> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <widget class="GtkButton" id="Please Click on the Button!"> <property name="label" translatable="yes">button</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_action_appearance">False</property> </widget> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </widget> </child> </widget> </glade-interface> 

1 Answer 1

3
self.window.show() 

At the end of __init__ should do it I think.

EDIT AFTER COMMENT...

self.window = self.wTree.get_widget("MainWindow")

but there is no window called "MainWindow", I think you've called your window "Hello world!", try loading that instead (or renaming your window in glade).

It may be a good idea to check that your window is actially found in the glade file as well.

window_name="Hello World!" self.window = self.wTree.get_widget(window_name) if (self.window): self.window.connect("destroy", gtk.main_quit) else: raise Exception("I couldn't find the window called "+window_name+"!") 
Sign up to request clarification or add additional context in comments.

2 Comments

I had to set the Visble option to yes in the common properties tab in the glade designer.The Program is working fine now.Thanks a lot :)
@hmms If this answered your question, you should mark it as correct by pressing the checkmark next to the answer. This will let everyone know the question is solved, rather than changing the title.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.