A
A
andrewMus2020-06-27 22:48:14
Python
andrewMus, 2020-06-27 22:48:14

How can I add my infinite loop to the Python program code from the telebot telegram bot (telebot) library in Python (Python)?

You need to create an infinite loop to check events,
well, of course I can create an infinite loop, but it slows down the bot, but it is necessary that if the events are correct, the bot sends a message, but continues to work...

from PyQt5 import QtWidgets
 
# Импортируем наш шаблон.
from myform import Ui_MainWindow
import sys
 
 
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()
 
 
app = QtWidgets.QApplication([])
application = mywindow()
application.show()

app.exec()

AMENDMENT the point is that app.exec() stops the code, and you can’t do it, we’ll change the task, we need the bot to send what we entered into the console, how do we constantly check if there is data if we put it before app.exec() then the program will not work, and if after - then it will not be executed until the end of the program ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wenderccc, 2020-06-28
@Wenderccc

Excuse me, but what does the telebot have to do with it? And so it can be done with multithreading.

S
shurshur, 2020-06-28
@shurshur

Instead of a loop, make a timer event like this: https://stackoverflow.com/questions/41327545/how-t...

F
fantvin, 2020-06-28
@fantvin

If the application is on qt5, you can use the QThread class
https://evileg.com/ru/post/579/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question