我有一个使用 PyQT5 为 Windows 和 macOS 构建的应用程序。目前,用户通过单击按钮检查更新,当有可用的新更新时,我将它们重定向到浏览器到我的服务器以下载最新的 .exe (Windows) 或 .pkg (macOS)。问题在于,如果用户在与前一版本不同的位置下载并安装最新版本,这将导致同一应用程序出现两个实例。
我想改善用户体验并制作一个像所有已建立的应用程序一样的自动更新程序。当用户单击更新时,应用程序应该下载新的更新,而不会给用户带来任何麻烦,并更新两个操作系统的应用程序。
对于 Windows,我使用 Pyinstaller 来生成 .exe 文件,然后使用 Inno Setup 来使其可执行。此外,对于 macOS,我使用 setuptools 来制作 .app 和 macOS 包应用程序以使其可执行。
如果有人可以帮助我为我的 PyQT5 应用程序实现更新功能,那就太好了。
你好,我制作了一个可以自我更新的程序,我使用的是 tkinter,但如果有相同的小部件,它应该适用于 PyQT5。我们使用 GitHub 从那里下载程序。另外我用的是windows,不知道mac下是否可以。这是我的代码:
import tkinter as tk #for you it is pyqt5
from tkinter import * #MessageBox and Button
import requests #pip install requests
import os #part of standard library
import sys #part of standard library
VERSION = 4
b1 = Button(frame, text = "Back", command = homepage)
b1.pack(ipadx= 10, ipady = 10, fill = X, expand = False, side = TOP)
checkupdate = Label(frame, text = "Looking for updates", font = ("Arial", 14))
checkupdate.pack()
try:
link = "https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/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.')
if mb1 is True:
filename = os.path.basename(sys.argv[0])
for file in os.listdir():
if file == filename:
pass
else:
os.remove(file)
exename = f'NameOfYourApp{float(check.text)}.exe'
code = requests.get("https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/NewUpdate.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
确保将所有 tkinter 代码转换为 PyQt5 小部件。另外,这是 Windows 将“https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/NewUpdate.exe”更改为“https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/NewUpdate” .app”适用于 Mac。如果这不起作用请评论,我会尽力将其转换为 PyQt5。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)