QkStart
我把这个程序命名为QkStart
代码
# -*- coding: utf-8 -*-
# Environment PyCharm
# File_name QkStart |User Pfolg
# 2024/10/19 22:06
import threading
import time
import pystray
from PIL import Image
from pystray import MenuItem, Menu
import os
import psutil
# import webbrowser# pyinstaller -F -w -i QkStart.png QkStart.pywdefault_exe = {"ClickShow": r"D:\Little_Tools\Clickshow\ClickShow.exe","Steam++": r"D:\Program Files\Steam++\Steam++.exe",
}
links = {"海螺AI": "https://hailuoai.com/","carbon": "https://carbon.now.sh/",
}
choice_exe = {"PixPin": r"D:\Software\PixPin\PixPin\PixPin.exe","PowerToys": r"D:\Program Files (x86)\PowerToys\PowerToys.exe","LANDrop": r"C:\Users\21460\AppData\Local\Programs\landrop-v2-electron\LANDrop.exe","KeyCastOW": r"D:\Little_Tools\KeyCastOW\KeyCastOW.exe","geek": r"D:\Little_Tools\geek.exe","FDM": r"D:\Program Files\Softdeluxe\Free Download Manager\fdm.exe",
}
all_target = {} # 整合字典
for i in [default_exe, links, choice_exe]:for j, k in i.items():all_target[j] = kdef open_exe(icon, item): # 使用类的默认传参来传递参数,然后检索程序并执行try:os.startfile(all_target.get(item.text))except OSError:icon.notify("{0}启动失败".format(item.text), "OSError")def open_link(icon, item):os.system("start {}".format(all_target.get(item.text)))# webbrowser.open_new_tab(all_target.get(item.text)) # 减少模块使用picture = r".\QkStart.png"menu = []# for i in [default_exe, links, choice_exe]:
# for key, value in i.items():
# menu.append(MenuItem(text=key, action=lambda v=value: open_exe(exe=v))) # 在 lambda 函数内部定义一个局部变量来存储当前的 value 值
# menu.append(Menu.SEPARATOR)
# menu.append(MenuItem(text='退出', action=lambda: icon.stop()))for key in default_exe:menu.append(MenuItem(text=key, action=open_exe))
menu.append(Menu.SEPARATOR)
for key in links:menu.append(MenuItem(text=key, action=open_link))
menu.append(Menu.SEPARATOR)
for key in choice_exe:menu.append(MenuItem(text=key, action=open_exe))
menu.append(Menu.SEPARATOR)
menu.append(MenuItem(text='退出', action=lambda: icon.stop()))# "原方法"
# menu = (MenuItem(text='ClickShow', action=lambda: open_exe(r"D:\Little_Tools\Clickshow\ClickShow.exe")),
# MenuItem(text='Steam++', action=lambda: open_exe(r"D:\Program Files\Steam++\Steam++.exe")),
# # MenuItem(text='菜单3', action=, enabled=False),
# Menu.SEPARATOR,
# MenuItem(text="海螺AI", action=lambda: open_link("https://hailuoai.com/")),
# MenuItem(text="carbon", action=lambda: open_link("https://carbon.now.sh/")),
# Menu.SEPARATOR,
# MenuItem(text='PixPin', action=lambda: open_exe(r"D:\Software\PixPin\PixPin\PixPin.exe")),
# MenuItem(text="PowerToys", action=lambda: open_exe(r"D:\Program Files (x86)\PowerToys\PowerToys.exe")),
# MenuItem(text="LANDrop", action=lambda: open_exe(
# r"C:\Users\21460\AppData\Local\Programs\landrop-v2-electron\LANDrop.exe")),
# MenuItem(text="KeyCastOW", action=lambda: open_exe(r"D:\Little_Tools\KeyCastOW\KeyCastOW.exe")),
# MenuItem(text="geek", action=lambda: open_exe(r"D:\Little_Tools\geek.exe")),
# MenuItem(text="FDM", action=lambda: open_exe(r"D:\Program Files\Softdeluxe\Free Download Manager\fdm.exe")),
# # MenuItem(text='我是点击图标的菜单', action=, default=True, visible=False),
# Menu.SEPARATOR,
# MenuItem(text='退出', action=on_exit),
# )
def auto_run():battery = psutil.sensors_battery()plugged = battery.power_pluggedif plugged:time.sleep(60)for exe in default_exe:os.startfile(default_exe.get(exe))time.sleep(3)if __name__ == '__main__':threading.Thread(target=auto_run).start()image = Image.open(picture)icon = pystray.Icon("QkStart", image, "快速启动应用", menu)icon.run()
🤓👆🏼
传递参数那块儿还是花了我一点时间的,结果是程序对内存的要求更高了
能干嘛
不会吹牛,就是简单的实现一下运行并自启动一些程序,如果把它放到startup文件夹里面就能实现开机自启(程序)了,它会在系统托盘处创建一个自己的图标,并自带一些功能
系统托盘:
自带的功能:
这个可以在代码里进行修改,只需要改一下字典里面的key和value就可以了