[Glade-users] How-to define my own class inheriting from gtk.Window and using glade file

On Wed, Apr 6, 2011 at 12:46 PM, Dominique Beauchamp
<lgd.beauchamp at gmail.com> wrote:
Hello all!
I'm using Glade with PyGTK (Python 2.6) and I'm quite happy about the
results. I succeed to define an application class like this:
class MyApp:

def __init__( self ):

Builder = gtk.Builder()
Builder.add_from_file( 'filename' )
Builder.connect_signals( self )
self.__MainWnd = Builder.get_object( 'MainWnd' )


But here is what I want to do: creating a class that derives from gtk.window
and being the main window defined within Glade.
class MyWnd( gtk.Window ):

def __init__( self, ??? ):


Here I want that the object returned by Builder.get_object( 'MainWnd' ) be
the object created by the actual class MyWnd because this class is in fact a
Is my explaination clear?
Maybe it is not possible this way and I have to create manually my own
gtk.Window then grab the VBox/HBox/Table with Builder.get_object() and add
it to my window. But it is not that cute.
Any idea will be welcome and thanks in advance!

Yes, you can define classes in python and use them in Glade and GtkBuilder.

For PyGTK & GTK+2 you must use Glade 3.6 or 3.8, if you migrate to
PyObject & GTK+3
then you must use Glade 3.10.

There is an example of how to setup Glade so that your custom python widgets
show up in Glade's palette, in Glade's API reference here:

Basically you just have to define a short xml catalog and have it in
when firing up Glade, and have a copy of the python source in the same


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]