3

I'm writing a little program that basically has a bunch of buttons that when you click one, it inputs a certain line of text into an online game I play. It would be a lot easier to use if the GUI would stay on top of the active game window so the user could be playing and then press a button on the panel without having to bring it to the front first.

Any help on how to do this would be great. Thanks

EDIT: Using tkinter

Kefka
  • 1,655
  • 2
  • 15
  • 25
  • What GUI framework do you use? And I think there's another problem, most games run in DirectX fullscreen, and this doesn't allows you to have a another window in front of the game. Think about using hotkeys! – leoluk Oct 13 '10 at 18:14
  • using tkinter for my gui – Kefka Oct 13 '10 at 18:16
  • and the game runs only in windowed mode. Its a sort of specialized program, does too many things that aren't doable with hotkeys (or at least, are horribly tedious to hotkey) – Kefka Oct 13 '10 at 18:17
  • Not super relevant, but the title of your question reminded me of this post: [What if two programs did this?](http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx) – Stigma Oct 13 '10 at 18:22
  • Does this answer your question? [How can I ensure that the application windows is always on top?](https://stackoverflow.com/questions/3678966/how-can-i-ensure-that-the-application-windows-is-always-on-top) – Wai Ha Lee Nov 27 '20 at 07:52

1 Answers1

14

You will need to provide the information on which GUI framework you are using for detailed answer at SO.

On windows you could do something like this with the handle of your window.

import win32gui
import win32con
win32gui.SetWindowPos(hWnd, win32con.HWND_TOPMOST, 0,0,0,0,
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)

Also with Tkinter, you might want to try. I have not tried it though.

root = Tk()
root.wm_attributes("-topmost", 1)
Community
  • 1
  • 1
pyfunc
  • 65,343
  • 15
  • 148
  • 136