gaetanm gaetanm - 2 years ago 176
Python Question

How to center a window with PyGObject

I'm currently trying to center my application window, but it seems to be impossible with PyGObject (GTK+ 3). Indeed, with pyGTK, I was doing it this way:


So this time I'm trying this:


set_position seems still existing, but the Gtk.WIN_POST_CENTER constant doesn't work:

AttributeError: 'gi.repository.Gtk' object has no attribute 'WIN_POS_CENTER'

Answer Source

pydoc tells you what you need to know:

>>> help(window.set_position)

Help on method set_position in module gi.repository.Gtk:

set_position(*args, **kwargs) method of gi.overrides.Gtk.Window instance
    set_position(self, position:Gtk.WindowPosition)

Gtk.WindowPosition wraps the enum values, so try:


edit: seems that for newer versions the docstring isn't displayed by help(window.set_position) anymore, use help(window) (or print(window.get_position.__doc__)) instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download