[英]How can I make my tkinter program autoupdate?
我正在使用 python 和 tkinter 创建一个小程序。 我想让程序检查用户使用的版本是否是最新版本。 如果没有,那么我想弹出一个窗口来提示用户更新。 然后,我希望我的软件自动为用户安装最新版本。 我该怎么做呢?
第一部分似乎很不言自明。 另一个堆栈溢出线程建议拥有一个具有正确版本的文本文件,然后对照用户拥有的文本文件进行检查。 我不确定如何让程序自行更新。
编辑:
添加一些细节。 是否可以使用 Python 下载 git 存储库并删除用户下载的旧版本?
这是我制作的代码:旁注:我不知道您是要下载多个还是只下载一个,我给出的示例只下载一个
from tkinter import *
import requests
import os
import sys
VERSION = 0
def check_updates():
try:
link = "https://raw.githubusercontent.com/User/Repo/Branch/SpecificFolderForUpdates/version.txt"
check = requests.get(link)
if float(VERSION) < float(check.text):
mb1 = messagebox.askyesno('Update Available', 'There is an update available. Click yes to update.') #confirming update with user
if mb1 is True:
filename = os.path.basename(sys.argv[0]) #gets current name of itself
savedrecordings = "Saved Recordings"
for file in os.listdir():
if file == filename: #Does not delete itself
pass
else:
os.remove(file) #removes all other files from the folder
exename = f'dcbot{float(check.text)}.exe'
code = requests.get("https://raw.githubusercontent.com/User/Repo/Branch/SpecificFolderToUpdate/file.exe", allow_redirects = True)
open(exename, 'wb').write(code.content)
root.destroy()
os.remove(sys.argv[0])
sys.exit()
elif mb1 == 'No':
pass
else:
messagebox.showinfo('Updates Not Available', 'No updates are available')
except Exception as e:
pass
root = tk.Tk()
root.geometry('800x400')
root.resizable(True, True)
root.title('Checking for updates...')
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.