PyQt挺好用

上源码

瞎搞的强制更新程序,来练手(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton,QLabel,QProgressBar,QWidget
from PyQt5.QtGui import QFont
from PyQt5.QtCore import QTimer


class updatE(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()

def initUI(self):
self.setGeometry(100, 100, 500, 200)
self.setWindowTitle("更新")

self.label=QLabel("发现新版本,在线更新",self)
self.label.setFont(QFont("Roman times", 15, QFont.Bold))
self.label.setGeometry(50, 40, 450, 80)

self.progressbar = QProgressBar(self)
self.progressbar.setGeometry(50, 140, 250, 40)
self.progressbar.setVisible(False)
self.timer=QTimer(self)
self.timer.timeout.connect(self.update_progressbar)


self.button = QPushButton("确定", self)
self.button.setGeometry(320, 140, 150, 40)
self.button.clicked.connect(self.update)


def update(self):
self.progressbar.setVisible(True)
self.label.setText("")
self.button.deleteLater()
self.progressbar.setValue(0)
self.progressbar.setMaximum(100)
self.timer.start(100)

def update_progressbar(self):
if self.progressbar.value() < 100:
self.progressbar.setValue(self.progressbar.value() + 1)
else:
self.timer.stop()
self.label.setText("更新完成")
if __name__ == '__main__':
app = QApplication(sys.argv)
window = updatE()
window.show()
sys.exit(app.exec_())