Tell me how to make the program run immediately, and not wait until the data is downloaded from the site? I need to first show the inscription "loading data ..." and then the title of the page ................ who can rewrite the code thanks in advance! Here is the code:
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import (QWidget, QPushButton, QLabel,QInputDialog, QApplication) from PyQt5.QtGui import QIcon,QFont,QColor,QPalette,QPixmap,QBrush from PyQt5 import QtCore from urllib.request import urlopen from lxml import html import threading class Пример(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(10, 30, 250, 200) self.setWindowTitle('PyQt5') self.label = QLabel(self) self.label.setText(str("загрузка данных...")) self.label.setGeometry(0,0,188,20) self.label2=QLabel(self) self.label2.setGeometry(0,0,188,20) if p2.is_alive()!=False: self.label.hide() self.label2.setText(str(proc2())) self.label2.show() def proc(): app = QApplication(sys.argv) пример=Пример() пример.show() sys.exit(app.exec_()) def proc2(): страница=urlopen('http://gismeteo.ru/weather-rudniy-4629').read() parsed_body=html.fromstring(страница) заголовок=parsed_body.xpath('//title/text()')[0] return заголовок p1=threading.Thread(target=proc) p2=threading.Thread(target=proc2) p1.start() p2.start() p1.join() p2.join()
threading.ThreadorQNetworkAccessManager. The second is even preferable, since you use Qt. - Avernial