A
A
andrewMus2020-07-04 21:46:07
Python
andrewMus, 2020-07-04 21:46:07

How to create a program in python (python) pyqt + telebot?

I wrote such a program, but it does not work, the window opens and immediately closes, I am silent about the telegram bot, I don’t understand what the problem is?
The essence of the program: we send messages through the console, it appears in the program (in the graphical interface) and we send it with the button ... Separately, it works fine, but when I collect it at once, it doesn’t. I searched, but did not find anything sensible ... I
thought to create 2 threads, in one pyqt, and in another telebot and that's it, but not everything is so simple ...

import threading
import telebot
from PyQt5 import QtWidgets
from myform import Ui_MainWindow
import sys

x=0
y=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()
        send()
        


def loop():
    while True:
        global x
        x = input()
        send()
def mainin():
    app = QtWidgets.QApplication([])
    application = mywindow()
    application.show()


bot = telebot.TeleBot('**********************************************')

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет, ты написал мне /start')

@bot.message_handler(content_types=['text'])
def send_text(message):
    #y=message.text.lower()
    pass
    # ответы на вопросы...
def send():
    bot.send_message("*********", x)
    #pass

t = threading.Thread(target=loop, args=())
t.start()
d = threading.Thread(target=mainin, args=())
d.start()

bot.polling()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question