Answer the question
In order to leave comments, you need to log in
How to update a PyQt application?
I'm starting to develop an application for VK on PyQt5. Created a simple window with the number of messages. I want the application to refresh every second and check if I have new messages. How can I do it? Here is the source code:
import sys
from PyQt5 import QtWidgets
from PyQt5.QtCore import QTimer
import playsound
from core import count_messages
from GUI import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.update_message
def update_message(self):
unread = count_messages()
old = 0
if unread - old > 0:
playsound.playsound('new_message.mp3')
old = unread
else:
old = unread
self.messages.setText(f'У вас {unread} непрочитанных сообщений!')
def start_app(name_class):
app = QtWidgets.QApplication(sys.argv)
window = name_class()
window.show()
app.exec_()
if __name__ == '__main__':
start_app(MainWindow)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question