简体   繁体   English

如何使我的 tkinter 程序自动更新?

[英]How can I make my tkinter program autoupdate?

I'm using python and tkinter to create a little program.我正在使用 python 和 tkinter 创建一个小程序。 I'd like to make the program check if the version the user is using is the most recent version.我想让程序检查用户使用的版本是否是最新版本。 If not, then I'd like a window pop up to prompt the user to update.如果没有,那么我想弹出一个窗口来提示用户更新。 Then, I'd like my software to automatically install the newest version for the user.然后,我希望我的软件自动为用户安装最新版本。 How would I go about doing this?我该怎么做呢?

The first part seems pretty self-explanatory.第一部分似乎很不言自明。 A different stack overflow thread suggests having a text file with the correct version and then checking that against a text file that the user has. 另一个堆栈溢出线程建议拥有一个具有正确版本的文本文件,然后对照用户拥有的文本文件进行检查。 I'm not sure how to get the program to update itself though.我不确定如何让程序自行更新。

Edit:编辑:

adding some detail.添加一些细节。 Is it possible to use Python to download a git repository and deleting the old version the user has downloaded?是否可以使用 Python 下载 git 存储库并删除用户下载的旧版本?

Here is the code I made: Side Note: I dont know if you would want to download multiple or just one, the example I gave just download one这是我制作的代码:旁注:我不知道您是要下载多个还是只下载一个,我给出的示例只下载一个

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM