How to center a window with PyGObject
Asked Answered
T

1

17

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:

window.set_position(gtk.WIN_POS_CENTER)

So this time I'm trying this:

window.set_position(Gtk.WIN_POST_CENTER)

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'

Tillandsia answered 5/5, 2013 at 21:12 Comment(0)
A
20

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:

window.set_position(Gtk.WindowPosition.CENTER)

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.

Ancheta answered 5/5, 2013 at 21:22 Comment(1)
help(Gtk.Window.set_position)Cyanic

© 2022 - 2024 — McMap. All rights reserved.