在Python中操作屏幕缓冲区

发布于 2024-08-11 07:45:53 字数 84 浏览 2 评论 0原文

我知道这是一个不太可能的事情,但我想知道 Python 是否有办法操纵屏幕缓冲区。具体来说,我希望能够在按下组合键时使桌面变灰并突出显示窗口。这有可能吗?

I know this is a long shot, but I was wondering if Python had a way to manipulate the screen buffer. Specifically, I want to be able to gray-out my desktop and highlight my windows when I press a key combination. Is this in the realm of possibility?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掀纱窥君容 2024-08-18 07:45:53

从您的问题和随后的评论来看, PyQt 将是一个不错的选择,您将有一个三个平台的通用代码。

不过,您必须使用库函数将其开发为 GUI,这也意味着您必须重新考虑 GUI 可能性方面您到底想要什么,并以尊重通常的 GUI 约定的方式:用户可能不想要您的应用程序可以修改他们最喜欢的桌面背景或表现得很奇怪。

例如,有一种方法可以将您的应用程序带到前台 (答案中给出的示例是 C++ 语言,但 Python 中提供了等效方法,并且代码非常相似)。

Qt 最初是一个 C++ 框架,最近被诺基亚收购,如果您也熟悉该语言,您应该认为在决定选择哪个之前就结束了,但无论如何 PyQt 不会让你失望,它相当成熟和稳定。

关于许可证,如果这是您关心的问题之一,PyQt 是 GPL,并且还提供商业许可证。另一个 Python Qt 移植正在使用 LGPL 许可证进行中,由诺基亚在 PyQt 作者拒绝更改其许可证后推动: PySide,但它仍处于早期开发阶段。

最后,我不得不提的是,Qt 并不是唯一的 Python GUI 框架,通过搜索,您会发现与该主题相关的其他问题以及其他建议:

From your question and the comments that followed, PyQt would be a good choice, you would have a common code for the three platforms.

You have to develop it as a GUI though, using the library functions, it also means you will have to rethink what you exactly want in terms of GUI possibilities, and in a way that respects the usual GUI conventions: users probably don't want your application to modify their favourite desktop background or to behave weirdly.

For example, there is a way to bring your application to the foreground (the examples given in answer are in C++ but equivalent methods are available in Python and the code would be very similar).

Qt is originally a C++ framework, recently acquired by Nokia, if you are also familiar with that language you should think it over before deciding which to choose, but in any case PyQt will not let you down, it is quite mature and stable.

Regarding the license, in case it's one of your concerns, PyQt is GPL and a commercial license is also available. Another Python Qt porting is in the works with a LGPL license, pushed by Nokia following the refusal from the PyQt author to change their license: PySide, but it is still in its early development.

Finally, I have to mention that Qt isn't the only GUI framework for Python, by searching you will find other questions related to that topic on SO, with other suggestions:

三月梨花 2024-08-18 07:45:53

不要将桌面“变灰”,而是尝试在整个屏幕上覆盖灰色的半透明图像,然后确保您的窗口位于其上方。您可能会面临一些小限制;例如,我根本不知道是否可以覆盖 mac 菜单栏(而且我不确定您是否愿意)。

Instead of "graying out" the desktop, try to overlay a gray, semi-transparent image over the entire screen and then make sure your window is on top of that. You may face a couple of minor limitations; for example, I don't know off the top of my head if it's possible to overlay the mac menubar (and I'm not sure you'd want to).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文