0

I'm using python and tkinter to create a little program. 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?

1 Answers1

1

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()
Dodu
  • 109
  • 2
  • 8
  • to download mutliple files change the part of the code where it will get the content, to download the entire git repo (20 lines above from bottom) – Dodu Jun 02 '22 at 13:09