gpt4 book ai didi

python - 如何在 StatusIcon 上显示文本而不是设置图标?

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:52 25 4
gpt4 key购买 nike

我是 Gtk 和 Python 的初级开发人员。我正在尝试创建一个 gtk.StatusIcon 来显示文本字符串而不是图标。我如何使用 PixBuf 或任何其他方式完成此操作?

谢谢。

最佳答案

使用 Python 和 GTK3 的示例:

from gi.repository import Gtk

class TextStatusIcon:
def __init__(self):
self.statusicon = Gtk.StatusIcon()
self.statusicon.connect("popup-menu", self.right_click_event)

window = Gtk.OffscreenWindow()
window.add(Gtk.Label("text"))
window.connect("damage-event", self.draw_complete_event)
window.show_all()

def draw_complete_event(self, window, event):
self.statusicon.set_from_pixbuf(window.get_pixbuf())

def right_click_event(self, icon, button, time):
Gtk.main_quit()

TextStatusIcon()
Gtk.main()

不幸的是,大多数系统托盘将图标的高度限制在一个非常小的尺寸,并且 Gtk.StatusIcon 会自动缩小 PixBuf,以便宽度和高度都小于高度限制。这严重限制了您可以使用 Gtk.StatusIcon 有效显示的文本量。

参见 https://github.com/PaulSD/Tray_Apps/tree/master/gtktrayicon对于一个库(除了 Gtk 之外还可以安装),它提供了一个 API 来实现更通用的系统托盘小程序,并支持任意长度的文本字符串。参见 https://github.com/PaulSD/Tray_Apps获取使用该库的示例代码。

关于python - 如何在 StatusIcon 上显示文本而不是设置图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7748183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com