How do I get the size of a pygtk window?

后端 未结 2 1509
独厮守ぢ
独厮守ぢ 2021-01-06 17:27

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 return

2条回答
  •  抹茶落季
    2021-01-06 18:22

    This seems to fix your problem:

    import gtk
    
    def print_size(widget, data=None):
        print window.get_size()
    
    def delete_event(widget, data=None):
        print window.get_size()
        return False
    
    def destroy(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.

提交回复
热议问题