python - 如何让我的程序始终显示在最前面

标签 python linux ubuntu pygame

计划信息和问题
我创建了一个 Python程序使用 Pygame 模块 在显示器上显示广告。
它在屏幕上显示广告但是一旦我启动不同的应用程序,如 kodi、vlc 或 chrome 等,它就会落后于这些应用程序。
问题是:如果这些应用程序在我的广告程序之后启动,则程序运行但在这些应用程序之后。
理想工作

  1. Program Laucnhed
  2. Ad Displayed on screen
  3. Launched Other Application
  4. The Program still displayes the ad on top of screen.

系统信息
操作系统 : Linux - Ubuntu 20
语言 : Python
模块 : Pygame, Pymovie, GTK3+
建筑 :amd64
桌面环境 : 开箱
代码启动 : CLI 使用 bash 脚本启动广告的 python 程序。
广告示例截图
Advertiesment Sample
请帮忙!
谢谢你。

最佳答案

看起来我能找到的最佳答案来自这个过时的网站 (https://www.mail-archive.com/pygtk@daa.com.au/msg01370.html)
他们说要使用下面的代码,它应该适用于所有操作系统......事情从来没有那么容易

transient.set_transient_for(main_window)
或者我还有其他四个答案哈哈
取自 (How to keep a python window on top of all others (python 3.1))
stackoverflow 用户 pyfunc 说对于 windows 你可以做
import win32gui
import win32con
win32gui.SetWindowPos(hWnd, win32con.HWND_TOPMOST, 0,0,0,0,
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
由于这仅适用于 Windows,我认为您应该尝试 python-tinker,我相信它适用于 linux
root = Tk()
root.wm_attributes("-topmost", 1)
whatnick 还说你可以使用 PyGTK
gtk.Window.set_keep_above
引用:How to make python window run as "Always On Top"?
让我知道这些是否对您有用,我将继续寻找更好的答案。

关于python - 如何让我的程序始终显示在最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70936073/

相关文章:

node.js - NodeJS/MongoDB - 避免 mongoose 节省错误的当前时间

ubuntu - 给定md5 Hash时如何查找特定文件

sql-server - 在 Ubuntu 上使用 perl 的 undefined symbol SQLAllocHandle

python - 在 Django 模板中包含 url 变量

python - python中对象的按位处理

c++ - 如何在 Linux 上控制(和模拟)显示器/投影仪?

linux - 调度器的工作

python - 在 python 中导入 hid 会导致错误 "hid.so: undefined symbol: libusb_open"

python - 从 PIL 导入图像,ImageTk ImportError : cannot import name ImageTk

linux - udev 规则在链接名称中使用 ATTRS{serial} 为 USB 设备生成符号链接(symbolic link)