其他分享
首页 > 其他分享> > 这个版本号,贼顺!

这个版本号,贼顺!

作者:互联网

今天,我写好了Easy PyPI v1.2.3

这个版本主要是BUG的修复(至少从使用者眼中来看)

具体更新

接下来就是喜闻乐见的代码!

import os
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.filedialog import askdirectory
import webbrowser
from threading import Thread
import sys

sdo=False
sdi=False

if len(sys.argv)>=1 and '-debug' in sys.argv:
    sdi=True

def showDebug(show_info=False):
    global sdo,sdo_btn,sdi
    if show_info:
        if sdi:
            sdi=False
            sdi_btn['text']='显示调试信息'
        else:
            sdi=True
            sdi_btn['text']='隐藏调试信息'
    else:
        if sdo:
            win.geometry('300x420')
            sdo_btn['text']='显示调试选项  v'
            sdo=False
        else:
            win.geometry('300x500')
            sdo_btn['text']='隐藏调试选项  ^'
            sdo=True

def dprint(msg):
    global sdi
    if sdi:
        print(msg)

def init():
    global py_path,pip_path,python_path
    try:
        dprint('正在读取配置信息')
        py_path_f=open("./py_path.cfg",'r',encoding='utf-8')
        py_path=py_path_f.read()
        dprint('根据配置信息,您的Python位于:'+py_path)
        py_path_f.close()
        pip_path=py_path+"/scripts/pip.exe"
        python_path=py_path+"/python.exe"
        dprint('读取完成')
        if py_path=='使用环境变量':
            dprint('使用环境变量')
            pip_path='pip'
            python_path='python'
    except Exception as e:
        dprint('读取设置失败:'+str(e))
        py_path=askdirectory(title='请选择Python安装路径')
        py_path_f=open("./py_path.cfg",'w',encoding='utf-8')
        py_path_f.write(py_path)
        py_path_f.close()
        pip_path=py_path+"/scripts/pip.exe"

def locate_pip(name=''):
    os.system("where pip")
    os.system("where pip3")
    print('==================================================')

def install(name,arg1='',arg2=''):
    os.system(pip_path+" install "+name+' -i https://pypi.douban.com/simple')
    print('==================================================')

def uninstall(name):
    print(name)
    if name=='pip':
        print('想什么呢?你准备卸载PyPI?')
    else:
        os.system(pip_path+" uninstall "+name)
    print('==================================================')

def upgrade(name=''):
    os.system(python_path+" -m pip install --upgrade pip -i https://pypi.douban.com/simple")
    print('==================================================')

def list_pkg(name=''):
    os.system(pip_path+" list")
    print('==================================================')

def about(name=''):
    os.system(pip_path+" --version")
    print('==================================================')
    
def start(func,p=''):
    #print(func)
    dprint('将向函数传入此类型的参数:'+str(type(p)))
    dprint('将向函数传入参数:'+p)
    #t=Thread(target=func,args=p)
    t=Thread(target=lambda:func(p))
    t.start()

#彩蛋
def egg():
    print('OHHHHHH!!!')
    print('这是一个彩蛋,竟然被你发现了!')
    print('庆祝本软件的版本号这么顺溜!Version 1.2.3耶!!')
    print('==================================================')

dprint('您传入了参数:'+str(sys.argv))

win=tk.Tk()
win.title('Easy PyPI V1.2.3')
win.geometry('300x420')
win.resizable(0,0)
win.update()

init()

name_enter=ttk.Entry(win)
name_enter.pack(fill=tk.X)

dprint('执行:     '+pip_path+' install '+'(库名)'+' -i https://pypi.douban.com/simple')

print('==================================================')

#功能区
ttk.Button(win,text='安装',command=lambda:start(install,name_enter.get())).pack(fill=tk.X)
ttk.Button(win,text='卸载',command=lambda:start(uninstall,name_enter.get())).pack(fill=tk.X)
ttk.Button(win,text='列出所有已经安装的库',command=lambda:start(list_pkg)).pack(fill=tk.X)
ttk.Button(win,text='更新PIP',command=lambda:start(upgrade)).pack(fill=tk.X)
ttk.Button(win,text='关于PIP',command=lambda:start(about)).pack(fill=tk.X)
ttk.Button(win,text='查看环境变量中有关PIP路径的配置',command=lambda:start(locate_pip)).pack(fill=tk.X)
sdo_btn=ttk.Button(win,text='显示调试选项  v',command=showDebug)
sdo_btn.pack(fill=tk.X)

#介绍区
tk.Label(win,text='介绍',bg='lightgrey').pack(fill=tk.X)
tk.Label(win,text='这个程序可以方便地从Pypi安装第三方库').pack(fill=tk.X)
tk.Label(win,text='默认使用豆瓣镜像源以提升速度').pack(fill=tk.X)

tk.Label(win,text='使用步骤',bg='lightgrey').pack(fill=tk.X)
tk.Label(win,text='1.在窗口顶部的输入框内输入库名').pack(fill=tk.X)
tk.Label(win,text='2.点击点击相关的功能按钮').pack(fill=tk.X)
tk.Label(win,text='3.等待操作完毕,目前已支持多线程').pack(fill=tk.X)
tk.Label(win,text='(不要关闭弹出的命令提示符)').pack(fill=tk.X)


tk.Button(win,text='2022 By 人工智障',bg='lightgrey',bd=0,command=lambda:webbrowser.open("https://www.cnblogs.com/totowang")).pack(fill=tk.X)


#调试选项
ttk.Button(win,text='显示输入的内容',command=lambda:print(name_enter.get()+'\n'+'==================================================')).pack(fill=tk.X)

sdi_btn=ttk.Button(win,text='显示调试信息',command=lambda:showDebug(show_info=True))
sdi_btn.pack(fill=tk.X)

ttk.Button(win,text='嘿!别错过我!',command=egg).pack(fill=tk.X)


win.mainloop()

 

标签:这个,版本号,text,tk,win,path,fill,pack
来源: https://www.cnblogs.com/TotoWang/p/ezpip_v123.html