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

  • Home
  • SEARCH
  • 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 374023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:21:54+00:00 2026-05-12T14:21:54+00:00

I am running a little program in python that launches a small window that

  • 0

I am running a little program in python that launches a small window that needs to stay on top of all the other windows. I believe this is OS specific, how is it done in GNU-Linux with GNOME?

[Update – Solution for Windows]

Lovely, I think I got it working. I am using Python 2.5.4 with Pygame 1.9.1 in Eclipse on Vista 64-bit. Thus, this is for windows systems. The SetWindowPos function is documented Here. I will refer to this in my explanation.

Imports:

from ctypes import windll

Then I set up a variable that calls the "SetWindowPos" in user32:

SetWindowPos = windll.user32.SetWindowPos

Now, let’s say I just made a window:

screen = pygame.display.set_mode((100,100), pygame.NOFRAME)

The next line is the key. This sets the window to be on top of other windows.

SetWindowPos(pygame.display.get_wm_info()['window'], -1, x, y, 0, 0, 0x0001)

Basically, You supply the hWnd(Window Handle) with the window ID returned from a call to display.get_wm_info(). Now the function can edit the window you just initialized.

The -1 is our hWndInsertAfter.

The MSDN site says:

A window can be made a topmost window either by setting the hWndInsertAfter parameter to HWND_TOPMOST and ensuring that the SWP_NOZORDER flag is not set, or by setting a window’s position in the Z order so that it is above any existing topmost windows. When a non-topmost window is made topmost, its owned windows are also made topmost. Its owners, however, are not changed.

So, the -1 makes sure the window is above any other existing topmost windows, but this may not work in all cases. Maybe a -2 beats a -1? It currently works for me. 🙂

The x and y specify the new coordinates for the window being set. I wanted the window to stay at its current position when the SetWindowPos function was called on it. Alas, I couldn’t find a way to easily pass the current window (x,y) position into the function. I was able to find a work around, but assume I shouldn’t introduce a new topic into this question.

The 0, 0, are supposed to specify the new width and height of the window, in pixels. Well, that functionality is already in your pygame.display.set_mode() function, so I left them at 0. The 0x0001 ignores these parameters.

0x0001 corresponds to SWP_NOSIZE and is my only uFlag. A list of all the available uFlags are on the provided documentation page. Some of their Hex representations are as follows:

  • SWP_NOSIZE = 0x0001
  • SWP_NOMOVE = 0x0002
  • SWP_NOZORDER = 0x0004
  • SWP_NOREDRAW = 0x0008
  • SWP_NOACTIVATE = 0x0010
  • SWP_FRAMECHANGED = 0x0020
  • SWP_SHOWWINDOW = 0x0040
  • SWP_HIDEWINDOW = 0x0080
  • SWP_NOCOPYBITS = 0x0100
  • SWP_NOOWNERZORDER = 0x0200
  • SWP_NOSENDCHANGING = 0x0400

That should be it! Hope it works for you!

Credit to John Popplewell at john@johnnypops.demon.co.uk for his help.

  • 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-12T14:21:54+00:00Added an answer on May 12, 2026 at 2:21 pm

    The question is more like which windowing toolkit are you using ? PyGTK and similar educated googling gave me this:

    
    gtk.Window.set_keep_above
    

    As mentioned previously it is upto the window manager to respect this setting or not.

    Edited to include SDL specific stuff
    Pygame uses SDL to do display work and apprently does not play nice with Windowing toolkits. SDL Window can be put on top is discussed here.

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

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's terrible. Your markup should be content, and your layout… May 12, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer You're looking for System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>. The new concurrent collections use… May 12, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer I think I would tend to go with WPF and… May 12, 2026 at 8:26 pm

Related Questions

Let's assume I browse a specific web page that uses JavaScript to update its
Is there any way of determining the current working directory of an already running
I am new to programming in general so please keep that in mind when
I've recently bought myself a new cellphone, running Windows Mobile 6.1 Professional. And of
I need a little help figuring this out because I'm new to stored procedures.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.