国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

pystray設(shè)置托盤圖標(biāo) 以及設(shè)置子菜單

2023-03-24 17:50 作者:Bojaka  | 我要投稿

有項目需要用到python設(shè)置托盤圖標(biāo) 發(fā)現(xiàn)pystray不錯 但網(wǎng)上的教程特別少

有的只有創(chuàng)建一個最基礎(chǔ)的一級菜單的教程?

于是我來教一下大家怎么創(chuàng)建多級菜單

首先給大家看一下可以搜索到的教程 <創(chuàng)建一級菜單>

import pystray

from PIL import Image

from pystray import MenuItem



def click_menu(icon, item):

? ? print("點(diǎn)擊了", item)



def on_exit(icon, item):

? ? icon.stop()



def notify(icon: pystray.Icon):

? ? icon.notify("我是消息類容", "消息標(biāo)題")



menu = (MenuItem(text='菜單1', action=click_menu), MenuItem(text='菜單2', action=click_menu),

? ? ? ? MenuItem(text='菜單3', action=click_menu, enabled=False),

? ? ? ? MenuItem(text='發(fā)送通知', action=notify),

? ? ? ? MenuItem(text='我是點(diǎn)擊圖標(biāo)的菜單', action=click_menu, default=True, visible=False),

? ? ? ? MenuItem(text='退出', action=on_exit),

? ? ? ? )

image = Image.open("logo.ico")

icon = pystray.Icon("name", image, "鼠標(biāo)移動到\n托盤圖標(biāo)上\n展示內(nèi)容", menu)

icon.run()

來 然后我教你怎么創(chuàng)建多級的 以下是我寫的一個類 用于托盤菜單控制的 相信你可以看懂 我就不解釋了 看一下就懂了?

from pystray import Icon as icon, Menu as menu, MenuItem as item

from PIL import Image


class TrayControl(object):

? def __init__(self) -> None:

? ? ? self.icon = None

? ? ? self.t_val = "二號"

? ? ? self.MenuItem = menu(item("選擇音效包",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? menu(

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? item("一號", action= lambda: setattr(self, "t_val", "一號"),checked=lambda item: self.t_val == "一號",),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? item("二號", action= lambda: setattr(self, "t_val", "二號"),checked=lambda item: self.t_val == "二號",),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ? ? item("退出", action=self.quit_app),

? ? ? ? ? ? ? ? ? ? ? ? ? )


? def quit_app(self):

? ? self.icon.stop()


? def create_tray(self):

? ? image = Image.new(mode="RGB", size=(260, 100), color="#ff0000")

? ? self.icon = icon("keysound",image,"keysound",menu = self.MenuItem)

? ? self.icon.run()


pystray設(shè)置托盤圖標(biāo) 以及設(shè)置子菜單的評論 (共 條)

分享到微博請遵守國家法律
渝北区| 安新县| 萨嘎县| 区。| 北碚区| 高雄县| 雷波县| 台州市| 云阳县| 桐梓县| 遵义县| 阳城县| 米脂县| 华坪县| 来凤县| 大港区| 眉山市| 淮南市| 政和县| 景德镇市| 德化县| 南城县| 泰宁县| 宜丰县| 永安市| 兰考县| 曲沃县| 灵武市| 南开区| 芮城县| 祁东县| 资源县| 扶余县| 类乌齐县| 建昌县| 临沂市| 留坝县| 柳河县| 九龙城区| 天峨县| 河东区|