本文来源吾爱破解论坛
好久没有发帖了,把自己最近捣鼓的东西发一下 1.png (776.45 KB, 下载次数: 0)
下载附件
保存到相册
2.png (910.2 KB, 下载次数: 0)
下载附件
保存到相册
因为电脑上面安装了许多的软件,所以桌面也很杂乱,特别的不美观
于是就自己写了一个快捷菜单程序,一个能顶35个快捷方式(大神勿喷)
先看下软件主界面(界面有点丑,不要介意^_^)
这是设置界面,可以在这里添加程序(添加之后需要重启程序才能在主界面找到添加的程序)
特别提醒:现在最多只能添加35个程序,多了的话也不会显示
下面就上代码了
[Python] 纯文本查看 复制代码[/size][/font]
[font=宋体][size=6]#导入库[/size][/font]
[font=宋体][size=6]from tkinter import *
import tkinter.filedialog
import tkinter.messagebox
from tkinter import ttk
import win32api
from PIL import ImageTk as itk
from PIL import Image as Img
import tkinter as tk[/size][/font]
[font=宋体][size=6]class MyMenu():
def __init__(self):
self.programname=[]
self.programpath = []
self.root = Tk()
self.root.geometry('1100x700+200+180')
self.root.resizable(False, False)
windowname = '\u5feb\u6377\u83dc\u5355'
self.root.title(windowname)
tabControl = ttk.Notebook(self.root)
menutab = ttk.Frame(tabControl)
tabControl.add(menutab, text='菜单')
settingtab = ttk.Frame(tabControl)
tabControl.add(settingtab, text='设置')
menupage = ttk.LabelFrame(menutab, text='菜单区', width=1100, height=700)
menupage.place(x=0, y=0)
settingpage = ttk.LabelFrame(settingtab, text='设置区', width=1100, height=700)
settingpage.place(x=0, y=0)
tabControl.pack(expand=1, fill='both')
#设置页面布局
# 设置背景图
bg1 = tk.Canvas(settingpage, width=1100, height=700, bg='white')
self.img1 = itk.PhotoImage(file="settingbg.jpg")
bg1.place(x=0, y=0)
bg1.create_image(0, 0, anchor=NW, image=self.img1)
# 文件路径 标签
self.filepathlabel = Label(settingpage, width=90, text='尚未选择文件',font='仿宋', bg='white')
self.filepathlabel.place(x=50, y=30)
self.choicepath=''
# 选择存档按钮 按钮
self.choicefilebutton = Button(settingpage, text='选择程序位置', font='仿宋', bg='yellow',command=self.ChoiceFileEvent)
self.choicefilebutton.place(x=300, y=150)
# 读取已选择存档内容 按钮
self.readfilebutton = Button(settingpage, text='添加此程序到菜单',command=self.saveselectedpath)
self.readfilebutton.place(x=600, y=150)
#self.readfilebutton.config(state='disable') # 设置按钮不可点击
#菜单页面布局
#菜单背景图片
bg2 = tk.Canvas(menupage, width=1100, height=700, bg='white')
self.img2 = itk.PhotoImage(file="menubg.jpg")
bg2.place(x=0, y=0)
bg2.create_image(0, 0, anchor=NW, image=self.img2)
pathslength = 0
with open('配置文件.ini','rb')as f:
self.paths=f.readlines()
for path in self.paths:
#print('$'+path.strip().decode('gbk')+'$')
if path.strip().decode('gbk')!='':
self.programname.append(path.decode('gbk').split('/')[-1].replace('.exe', '').strip())
self.programpath.append(path.decode('gbk').strip())
pathslength +=1
#print(self.programpath,self.programname)
#创建菜单按钮
menubuttons=[]
x=50
y=50
for i in range(0,35):
#print(self.programpath[i],self.programname[i],i)
menubutton=Button(menutab,text='<NULL>',width=15,height=5)
if i%7==0 and i!=0:
y=y+120
x=50
menubutton.config(bg='#FAEBD7')
menubutton.place(x=x,y=y)
x = x+150
menubuttons.append(menubutton)
#print(123,pathslength)
#添加35个按钮的监听事件
if(pathslength>0):
menubuttons[0].config(command=lambda :self.openprogram(self.programpath[0]),text=self.programname[0])
if (pathslength > 1):
menubuttons[1].config(command=lambda: self.openprogram(self.programpath[1]), text=self.programname[1])
if (pathslength > 2):
menubuttons[2].config(command=lambda: self.openprogram(self.programpath[2]), text=self.programname[2])
if (pathslength > 3):
menubuttons[3].config(command=lambda: self.openprogram(self.programpath[3]), text=self.programname[3])
if (pathslength > 4):
menubuttons[4].config(command=lambda: self.openprogram(self.programpath[4]), text=self.programname[4])
if (pathslength > 5):
menubuttons[5].config(command=lambda: self.openprogram(self.programpath[5]), text=self.programname[5])
if (pathslength > 6):
menubuttons[6].config(command=lambda: self.openprogram(self.programpath[6]), text=self.programname[6])
if (pathslength > 7):
menubuttons[7].config(command=lambda: self.openprogram(self.programpath[7]), text=self.programname[7])
if (pathslength > 8):
menubuttons[8].config(command=lambda: self.openprogram(self.programpath[8]), text=self.programname[8])
if (pathslength > 9):
menubuttons[9].config(command=lambda: self.openprogram(self.programpath[9]), text=self.programname[9])
if (pathslength > 10):
menubuttons[10].config(command=lambda: self.openprogram(self.programpath[10]), text=self.programname[10])
if (pathslength > 11):
menubuttons[11].config(command=lambda: self.openprogram(self.programpath[11]), text=self.programname[11])
if (pathslength > 12):
menubuttons[12].config(command=lambda: self.openprogram(self.programpath[12]), text=self.programname[12])
if (pathslength > 13):
menubuttons[13].config(command=lambda: self.openprogram(self.programpath[13]), text=self.programname[13])
if (pathslength > 14):
menubuttons[14].config(command=lambda: self.openprogram(self.programpath[14]), text=self.programname[14])
if (pathslength > 15):
menubuttons[15].config(command=lambda: self.openprogram(self.programpath[15]), text=self.programname[15])
if (pathslength > 16):
menubuttons[16].config(command=lambda: self.openprogram(self.programpath[16]), text=self.programname[16])
if (pathslength > 17):
menubuttons[17].config(command=lambda: self.openprogram(self.programpath[17]), text=self.programname[17])
if (pathslength > 18):
menubuttons[18].config(command=lambda: self.openprogram(self.programpath[18]), text=self.programname[18])
if (pathslength > 19):
menubuttons[19].config(command=lambda: self.openprogram(self.programpath[19]), text=self.programname[19])
if (pathslength > 20):
menubuttons[20].config(command=lambda: self.openprogram(self.programpath[20]), text=self.programname[20])
if (pathslength > 21):
menubuttons[21].config(command=lambda: self.openprogram(self.programpath[21]), text=self.programname[21])
if (pathslength > 22):
menubuttons[22].config(command=lambda: self.openprogram(self.programpath[22]), text=self.programname[22])
if (pathslength > 23):
menubuttons[23].config(command=lambda: self.openprogram(self.programpath[23]), text=self.programname[23])
if (pathslength > 24):
menubuttons[24].config(command=lambda: self.openprogram(self.programpath[24]), text=self.programname[24])
if (pathslength > 25):
menubuttons[25].config(command=lambda: self.openprogram(self.programpath[25]), text=self.programname[25])
if (pathslength > 26):
menubuttons[26].config(command=lambda: self.openprogram(self.programpath[26]), text=self.programname[26])
if (pathslength > 27):
menubuttons[27].config(command=lambda: self.openprogram(self.programpath[27]), text=self.programname[27])
if (pathslength > 28):
menubuttons[28].config(command=lambda: self.openprogram(self.programpath[28]), text=self.programname[28])
if (pathslength > 29):
menubuttons[29].config(command=lambda: self.openprogram(self.programpath[29]), text=self.programname[29])
if (pathslength > 30):
menubuttons[30].config(command=lambda: self.openprogram(self.programpath[30]), text=self.programname[30])
if (pathslength > 31):
menubuttons[31].config(command=lambda: self.openprogram(self.programpath[31]), text=self.programname[31])
if (pathslength > 32):
menubuttons[32].config(command=lambda: self.openprogram(self.programpath[32]), text=self.programname[32])
if (pathslength > 33):
menubuttons[33].config(command=lambda: self.openprogram(self.programpath[33]), text=self.programname[33])
if (pathslength > 34):
menubuttons[34].config(command=lambda: self.openprogram(self.programpath[34]), text=self.programname[34])
def openprogram(self,programpath):
#print('='*40)
#print(programpath)
win32api.ShellExecute(0, 'open', programpath, '', '', 1)
def saveselectedpath(self):
with open('配置文件.ini','a+')as f:
print('#'+self.choicepath.encode('gbk').decode('gbk')+'$')
if self.choicepath.encode('gbk').decode('gbk')!='':
f.write(self.choicepath.encode('utf-8').decode('utf-8')+'\n')
tkinter.messagebox.showinfo('提示', '添加程序成功\n(重启生效)')
else:
tkinter.messagebox.showinfo('提示', '未选择程序\n')
#获取exe文件路径及文件名
def ChoiceFileEvent(self):
filepath=tkinter.filedialog.askopenfilename(filetypes=[('EXE','*.exe')])
if(filepath!=''):
self.filepathlabel.config(text='您选择的文件是:'+filepath,bg='green')
self.choicepath=filepath
self.choicefilebutton.config(bg='green')
self.readfilebutton.config(state='active')
else:
self.filepathlabel.config(text='您没有选择任何文件,请重新选择')
self.choicepath=''
self.filepathlabel.config(bg='red')
self.choicefilebutton.config(bg='red')
self.readfilebutton.config(state='disable',bg='red')
if __name__ == '__main__':
menu=MyMenu()
menu.root.mainloop()
大家有什么建议或者不明白的可以留言告诉我,我看到就会回复的。
对了,软件添加的程序可以在"配置文件.ini"里直接添加修改删除,格式一定要与程序添加的格式一样,而且文件夹下的文件一定不要删,否则程序就打不开了
源码及成品软件下载链接在这里: https://pan.baidu.com/s/1TefUuKip3j3RWn75TeCISA 提取码: aeaa
版权声明:
本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。