Loading A Window Created Using GLADE in Python

Read {count} times since 2020

If you have created a window using Glade and want to display this window on your Python program containing the event handlers of the Window, then you should follow this tutorial.
This small code will load the Glade file and displays the window.
Note : The Glade Project file format should be GtkBuilder.
Now, let’s get down to the code. Create a Python file named window.py in the folder containing the glade file and put in the following contents :

import pygtk
import gtk
import gtk.glade
class SubinsWindow:
 def __init__(self):
  self.gladefile = "window.glade"
  self.glade = gtk.Builder()
  self.win=self.glade.get_object("window1") # Window Name in GLADE

  if __name__ == "__main__":<br />&nbsp;a = SubinsWindow()<br />&nbsp;gtk.main()

The first yellow backgrounded text has the name of the GLADE file.
The second yellow backgrounded text has the name of the GLADE Window. Normally It would be window1.
Execute the Python program by opening a terminal with the folder and execute the following command:

python window.py

Here is a sample window created using GLADE and executed in Python :

So, Now you know how to import a GLADE file in Python and display the window.
If you have any problems/suggestions/feedback just say it out in the comment box below.

Show Comments