Skip to content Skip to sidebar Skip to footer

How Do I Get The Size Of A Pygtk Window?

I'm trying to use gtk.window.get_size(), but it always just returns the default width and height. The documentation says The get_size() method returns a tuple containing the curre

Solution 1:

This seems to fix your problem:

import gtk

defprint_size(widget, data=None):
    print window.get_size()

defdelete_event(widget, data=None):
    print window.get_size()
    returnFalsedefdestroy(widget, data=None):
    gtk.main_quit()

window = gtk.Window()
window.connect('delete_event', delete_event)
window.connect('destroy', destroy)

button = gtk.Button(label='Print size')
button.connect('clicked', print_size)
window.add(button)

window.show_all()

gtk.main()

I think the key is calling get_size on the delete_event signal rather than the destroy signal. If you do it on the destroy signal, it's like you describe, it just returns the default size.

Solution 2:

Try running:

while gtk.events_pending():
    gtk.main_iteration_do(False)

right before calling window.get_size()

Post a Comment for "How Do I Get The Size Of A Pygtk Window?"