Answer the question
In order to leave comments, you need to log in
How to create an infinite pyqt loop, and when you enter text into the console, it is updated in a graphical application?
I searched quite a lot on this topic, but I didn’t find something understandable for me, I don’t understand how to use multitasking, I found examples using multitasking, substituted PyQt but the program either freezes or works itself but there is no infinite loop, can you please explain to me (with comments), or if there is some primer (maybe on the English-speaking Internet), then give a link, because I can’t find anything worthwhile ... I
imagine it somehow
from PyQt5 import QtWidgets
# Импортируем наш шаблон.
from myform import Ui_MainWindow
import sys
x=0
class mywindow(QtWidgets.QMainWindow):
def __init__(self):
super(mywindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# подключение клик-сигнал к слоту btnClicked
self.ui.pushButton.clicked.connect(self.btnClicked)
def btnClicked(self):
self.ui.label.setText("Вы нажали на кнопку!")
self.ui.label.adjustSize()
def loop():
while True:
x=input()
application.ui.label.setText(x)
#но как её вызвать (функцию) ?
app = QtWidgets.QApplication([])
application = mywindow()
application.show()
Answer the question
In order to leave comments, you need to log in
You need to run this function in a separate thread.
You can read about competitive programming.
https://habr.com/ru/post/318374/
import threading
def loop():
while True:
x=input()
application.ui.label.setText(x)
t = threading.Thread(target=loop, args=())
t.start()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question