python调用命令行统筹运行你的小工具

在本专栏中介绍了一些工具,这里相当于为它们编写了一个主菜单,方便你进行管理。

导入必要的库:

import sys
import tkinter
import os

定义一个函数,传入一个路径,运行对应目录下的工具:

def call(types):
    f2 = open("path.txt", "r", encoding="UTF-8")
    path = f2.readline()
    f2.close()
    os.system(command=f"start {path}\\{types}\\{types}.exe")  # 极其关键的一行
    sys.exit()

为主菜单编写ui:

def main():
    global screen
    screen = tkinter.Tk()  # 窗口初始化
    screen.title("凡尘的脚本")  # 设置标题
    screen.geometry("500x300+250+120")  # 设置窗口大小与初始化位置
    screen.iconbitmap("ironmouse.ico")  # 设置窗口图标
    screen.resizable(width=False, height=False)  # 禁止改变窗口大小!!!!!!
    # screen.bind("<Button-1>", click)
    # screen.bind('<Motion>', move)
    font1 = ("SimSun", 25)  # 设置主要字体
    tkinter.Canvas(screen, height=300, width=505, bg='grey').place(x=-5, y=0)
    tkinter.Button(screen, text="键鼠精灵", font=font1, command=lambda: call(types="键鼠精灵"), bg='#777777',
                   activebackground='#777777').place(x=40, y=30)
    tkinter.Button(screen, text="键盘音效", font=font1, command=lambda: call(types="键盘音效"), bg='#777777',
                   activebackground='#777777').place(x=40, y=200)
    tkinter.Button(screen, text="壁纸更换", font=font1, command=lambda: call(types="壁纸更换"), bg='#777777',
                   activebackground='#777777').place(x=250, y=30)
    tkinter.Button(screen, text="图片爬虫", font=font1, command=lambda: call(types="图片爬虫"), bg='#777777',
                   activebackground='#777777').place(x=250, y=115)
    screen.mainloop()

最后运行main即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值