Python簡單實現 軟件在線更新 在線下載(Python simple implementation of software online update and download)
文章來自:https://www.cnblogs.com/iAmSoScArEd/p/11199970.html 爬蟲、轉載請注明出處。
import tkinter.messagebox import requests VERSION_NOW='100'#1.0.0 UPDATE_DOWNLOAD_URL='http://www.url.com/a.zip' #新版本文件 VERSION_URL='http://www.url.com/version'#最新版本號 try: ver=request.get(VERSION_URL)#獲取最新版本號 #然后自己根據版本號對版本進行對比處理 #這里省略 #直接跳到更新代碼 tkinter.messagebox.showwarning(title='提示', message='發現新版本,點擊確定開始更新。更新時間跟網速有關,請耐心等待!') newFile=requests.get(UPDATE_DOWNLOAD_URL) with open("newFile_update.zip","wb") as fp: fp.write(newFile.content) except: tkinter.messagebox.showwarning(title='警告', message='更新失敗,請檢查網絡!') tkinter.messagebox.showwarning(title='提示', message='新版本軟件下載完成!請在當前軟件目錄查看(文件名:newFile_update.zip)並使用新版本。')