Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:30:06+00:00 2026-05-26T13:30:06+00:00

I’m trying to use gtk.window.get_size(), but it always just returns the default width and

  • 0

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 current width and
height of the window. If the window is not on-screen, it returns the
size PyGTK will suggest to the window manager for the initial window
size. The size obtained by the get_size() method is the last size
received in a configure event, that is, PyGTK uses its locally-stored
size, rather than querying the X server for the size. As a result, if
you call the resize() method then immediately call the get_size()
method, the size won’t have taken effect yet. After the window manager
processes the resize request, PyGTK receives notification that the
size has changed via a configure event, and the size of the window
gets updated.

I’ve tried resizing the window manually and waiting a minute or so, but I still get the default width and height.

I’m trying to use this to save the window size on quit so that I can restore it on start. Is there a better way to do this?

Here’s the code snipit I have for my main quit.

def on_main_window_destroy(self, widget, data=None):
    if self.view.current_view.layout == 'list':
        self.view.current_view.set_column_order()

    width = self.main_window.get_size()[0]
    height = self.main_window.get_size()[1]
    #test statement
    print (width, height)

    self.prefs.set_size_prefs(width, height)
    self.prefs.set_view_prefs(self.view.current_view.media, self.view.current_view.layout)
    gtk.main_quit()

I think I understand what’s happening now. This is inside the destroy signal, so by the time the code gets called, the window is already gone. Is there a more canonical way of handling window resizing? I was hoping to avoid handling resize events everytime the user resized the window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:30:06+00:00Added an answer on May 26, 2026 at 1:30 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.