1. 程式人生 > 其它 >Easy PyPI V1.3.0釋出!反饋、幫助功能上線了!

Easy PyPI V1.3.0釋出!反饋、幫助功能上線了!

本次更新內容:

  • 增加了內建瀏覽器
  • 增加了線上幫助、反饋的入口
  • 增加了檢視庫的詳細資訊的功能,主要是顯示PyPI官網上的內容
  • 程式碼:內建瀏覽器本是為了彩蛋而製作!

程式碼

import os
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.filedialog import askdirectory
import webbrowser
from threading import Thread
import sys
from tkwebview2.tkwebview2 import WebView2
###
from time import
sleep 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,egg_count if show_info: if sdi: sdi=False sdi_btn['text']='顯示除錯資訊' else: sdi=True sdi_btn[
'text']='隱藏除錯資訊' else: if sdo: win.geometry('300x340') sdo_btn['text']='顯示除錯選項 v' egg_count=0 sdo=False else: win.geometry('300x450') 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): 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 view(url): webwin=tk.Tk() webwin.title('網頁檢視器') frame=WebView2(webwin,1200,680) frame.load_url(url) frame.pack(fill=tk.BOTH,expand=True) ttk.Button(webwin,text='在瀏覽器開啟',command=lambda:webbrowser.open(url)).pack(fill=tk.X,side=tk.BOTTOM) webwin.mainloop() #彩蛋 def egg(): #webbrowser.open("https://player.bilibili.com/player.html?aid=798361795&cid=270775854&page=1&high_quality=0&danmaku=1") eggwin=tk.Tk() eggwin.title('你發現了彩蛋!') countdown_label=tk.Label(eggwin,text='你發現了彩蛋!',font=('微軟雅黑','50')) countdown_label.pack() eggwin.update() sleep(2) countdown=3 for i in range(0,3): countdown_label['text']='驚喜揭曉!'+str(countdown) eggwin.update() countdown-=1 sleep(1) countdown_label.destroy() frame=WebView2(eggwin,960,540) frame.load_url("https://player.bilibili.com/player.html?aid=798361795&cid=270775854&page=1&high_quality=0&danmaku=1&t=0.0001") frame.pack(fill=tk.BOTH,expand=True) eggwin.title('你被騙了') eggwin.mainloop() dprint('您傳入了引數:'+str(sys.argv)) win=tk.Tk() win.title('Easy PyPI V1.3.0') win.geometry('300x340') 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:view("https://pypi.org/project/"+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) #介紹區被刪去,因為它被CHM所替代 tk.Button(win,text='2022 By 人工智障',bg='lightgrey',bd=0,command=lambda:view("https://www.cnblogs.com/totowang")).pack(fill=tk.X) tk.Button(win,text='問題反饋',bg='lightgrey',bd=0,command=lambda:view("https://support.qq.com/products/384388?")).pack(fill=tk.X) tk.Button(win,text='幫助',bg='lightgrey',bd=0,command=lambda:view("http://rgzz.great-site.net/soft/ezpip/WebHelp/")).pack(fill=tk.X) tk.Button(win,text='開源許可證',bg='lightgrey',bd=0,command=lambda:view("https://www.mozilla.org/en-US/MPL/1.1/")).pack(fill=tk.X) #除錯選項 ttk.Button(win,text='顯示輸入的內容',command=lambda:print(name_enter.get()+'\n'+'==================================================')).pack(fill=tk.X) ttk.Button(win,text='使用內建網頁檢視器開啟輸入的網址',command=lambda:view(name_enter.get())).pack(fill=tk.X) sdi_btn=ttk.Button(win,text='顯示除錯資訊',command=lambda:showDebug(show_info=True)) sdi_btn.pack(fill=tk.X) egg_btn=ttk.Button(win,text='嘿!別錯過我!',command=egg) egg_btn.pack(fill=tk.X) win.mainloop()

 

import osimport tkinter as tkimport tkinter.ttk as ttkfrom tkinter.filedialog import askdirectoryimport webbrowserfrom threading import Threadimport sysfrom tkwebview2.tkwebview2 import WebView2###from time import sleep
sdo=Falsesdi=False

if len(sys.argv)>=1 and '-debug' in sys.argv:    sdi=True
def showDebug(show_info=False):    global sdo,sdo_btn,sdi,egg_count    if show_info:        if sdi:            sdi=False            sdi_btn['text']='顯示除錯資訊'        else:            sdi=True            sdi_btn['text']='隱藏除錯資訊'    else:        if sdo:            win.geometry('300x340')            sdo_btn['text']='顯示除錯選項  v'            egg_count=0            sdo=False        else:            win.geometry('300x450')            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):    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 view(url):    webwin=tk.Tk()    webwin.title('網頁檢視器')    frame=WebView2(webwin,1200,680)    frame.load_url(url)    frame.pack(fill=tk.BOTH,expand=True)    ttk.Button(webwin,text='在瀏覽器開啟',command=lambda:webbrowser.open(url)).pack(fill=tk.X,side=tk.BOTTOM)    webwin.mainloop()
#彩蛋def egg():    #webbrowser.open("https://player.bilibili.com/player.html?aid=798361795&cid=270775854&page=1&high_quality=0&danmaku=1")    eggwin=tk.Tk()    eggwin.title('你發現了彩蛋!')    countdown_label=tk.Label(eggwin,text='你發現了彩蛋!',font=('微軟雅黑','50'))    countdown_label.pack()    eggwin.update()    sleep(2)    countdown=3    for i in range(0,3):        countdown_label['text']='驚喜揭曉!'+str(countdown)        eggwin.update()        countdown-=1        sleep(1)    countdown_label.destroy()    frame=WebView2(eggwin,960,540)    frame.load_url("https://player.bilibili.com/player.html?aid=798361795&cid=270775854&page=1&high_quality=0&danmaku=1&t=0.0001")    frame.pack(fill=tk.BOTH,expand=True)    eggwin.title('你被騙了')    eggwin.mainloop()    
dprint('您傳入了引數:'+str(sys.argv))
win=tk.Tk()win.title('Easy PyPI V1.3.0')win.geometry('300x340')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:view("https://pypi.org/project/"+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)
#介紹區被刪去,因為它被CHM所替代
tk.Button(win,text='2022 By 人工智障',bg='lightgrey',bd=0,command=lambda:view("https://www.cnblogs.com/totowang")).pack(fill=tk.X)tk.Button(win,text='問題反饋',bg='lightgrey',bd=0,command=lambda:view("https://support.qq.com/products/384388?")).pack(fill=tk.X)tk.Button(win,text='幫助',bg='lightgrey',bd=0,command=lambda:view("http://rgzz.great-site.net/soft/ezpip/WebHelp/")).pack(fill=tk.X)tk.Button(win,text='開源許可證',bg='lightgrey',bd=0,command=lambda:view("https://www.mozilla.org/en-US/MPL/1.1/")).pack(fill=tk.X)

#除錯選項ttk.Button(win,text='顯示輸入的內容',command=lambda:print(name_enter.get()+'\n'+'==================================================')).pack(fill=tk.X)ttk.Button(win,text='使用內建網頁檢視器開啟輸入的網址',command=lambda:view(name_enter.get())).pack(fill=tk.X)
sdi_btn=ttk.Button(win,text='顯示除錯資訊',command=lambda:showDebug(show_info=True))sdi_btn.pack(fill=tk.X)
egg_btn=ttk.Button(win,text='嘿!別錯過我!',command=egg)egg_btn.pack(fill=tk.X)

win.mainloop()