Answer the question
In order to leave comments, you need to log in
Variable not working in Qt designer python3 with socks?
I connect socks and I receive values of variables. But when the push button is pressed, the entire program crashes. I post the code in two lines.
from PyQt5 import QtWidgets
from mydes import Ui_Form # импорт нашего сгенерированного файла
from PyQt5.QtCore import pyqtSignal, QObject
import sys
import socket
import socks
import requests
import time
class mywindow(QtWidgets.QMainWindow):
def __init__(self):
super(mywindow, self).__init__()
super().__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ui.BUTTONpush.clicked.connect(self.btnClicked)
self.ui.ProxyInput.textChanged.connect(self.text_proxy) # +++
self.proxy = self.ui.ProxyInput.text()
self.ui.PortInput.textChanged.connect(self.text_port) # +++
self.port = self.ui.PortInput.text()
self.ui.TokenInput.textChanged.connect(self.text_token) # +++
self.token = self.ui.TokenInput.text()
self.ui.ChatInput.textChanged.connect(self.text_chatid) # +++
self.chatid = self.ui.ChatInput.text()
def text_proxy(self, text): # +++
self.proxy = text
print(self.proxy, text)
def text_port(self, text): # +++
self.port = text
print(self.port)
def text_token(self, text): # +++
self.token = text
print(self.token)
def text_chatid(self, text): # +++
self.chatid = text
print(self.chatid)
self.ui.EnterText.textChanged.connect(self.text_changed) # +++
self.text = self.ui.EnterText.text()
def text_changed(self, text): # +++
self.text = text
def btnClicked(self):
#self.ui.label.setText("Вы нажали на кнопку!")
# Если не использовать, то часть текста исчезнет.
#self.ui.label.adjustSize()
ip = self.ui.ProxyInput.text()# = ip
port = self.ui.PortInput.text()# = port
api_token = self.ui.TokenInput.text()# = api_token
chat_id = self.ui.ChatInput.text()# = chat_id
textik = self.ui.EnterText.text()
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, port)
socket.socket = socks.socksocket
print('Нажали на кнопку' )
print(self.ui.EnterText.text(), 'введеный текс')
h = requests.get(f"https://api.telegram.org/bot{api_token}/sendMessage?chat_id={chat_id}&text={str(textik)}")
self.ui.EnterText.clear()
def mostrarFuncion(self):
minombre = self.EnterText.text()
micontrasena = self.contrasena.text()
print("Nombre: " +minombre + " Contrasena: ")
self.setWindowTitle("Nombre: " +minombre + " Contrasena:")
app = QtWidgets.QApplication([])
application = mywindow()
application.show()
sys.exit(app.exec())
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '1.ui'
#
# Created by: PyQt5 UI code generator 5.13.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowModality(QtCore.Qt.NonModal)
Form.setEnabled(True)
Form.resize(342, 380)
Form.setMinimumSize(QtCore.QSize(342, 380))
Form.setMaximumSize(QtCore.QSize(342, 380))
self.BUTTONpush = QtWidgets.QPushButton(Form)
self.BUTTONpush.setEnabled(True)
self.BUTTONpush.setGeometry(QtCore.QRect(0, 350, 341, 31))
self.BUTTONpush.setObjectName("BUTTONpush")
self.scrollArea = QtWidgets.QScrollArea(Form)
self.scrollArea.setEnabled(True)
self.scrollArea.setGeometry(QtCore.QRect(0, 120, 341, 191))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 339, 189))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.listView = QtWidgets.QListView(self.scrollAreaWidgetContents)
self.listView.setEnabled(True)
self.listView.setGeometry(QtCore.QRect(0, 0, 341, 191))
self.listView.setObjectName("listView")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.EnterText = QtWidgets.QLineEdit(Form)
self.EnterText.setEnabled(True)
self.EnterText.setGeometry(QtCore.QRect(0, 310, 341, 41))
self.EnterText.setObjectName("EnterText")
minombre = self.EnterText.text()
print(minombre)
self.textEdit = QtWidgets.QTextEdit(Form)
self.textEdit.setEnabled(False)
self.textEdit.setGeometry(QtCore.QRect(0, 0, 341, 31))
self.textEdit.setObjectName("textEdit")
self.ProxyInput = QtWidgets.QLineEdit(Form)
self.ProxyInput.setEnabled(True)
self.ProxyInput.setGeometry(QtCore.QRect(60, -1, 281, 31))
self.ProxyInput.setObjectName("ProxyInput")
self.textEdit_2 = QtWidgets.QTextEdit(Form)
self.textEdit_2.setEnabled(False)
self.textEdit_2.setGeometry(QtCore.QRect(0, 30, 341, 31))
self.textEdit_2.setObjectName("textEdit_2")
self.PortInput = QtWidgets.QLineEdit(Form)
self.PortInput.setEnabled(True)
self.PortInput.setGeometry(QtCore.QRect(60, 30, 281, 31))
self.PortInput.setObjectName("PortInput")
self.textEdit_3 = QtWidgets.QTextEdit(Form)
self.textEdit_3.setEnabled(False)
self.textEdit_3.setGeometry(QtCore.QRect(0, 60, 341, 31))
self.textEdit_3.setObjectName("textEdit_3")
self.TokenInput = QtWidgets.QLineEdit(Form)
self.TokenInput.setEnabled(True)
self.TokenInput.setGeometry(QtCore.QRect(60, 60, 281, 31))
self.TokenInput.setObjectName("TokenInput")
self.textEdit_4 = QtWidgets.QTextEdit(Form)
self.textEdit_4.setEnabled(False)
self.textEdit_4.setGeometry(QtCore.QRect(0, 90, 341, 31))
self.textEdit_4.setObjectName("textEdit_4")
self.ChatInput = QtWidgets.QLineEdit(Form)
self.ChatInput.setEnabled(True)
self.ChatInput.setGeometry(QtCore.QRect(60, 90, 281, 31))
self.ChatInput.setObjectName("ChatInput")
self.retranslateUi(Form)
# self.BUTTONpush.clicked.connect(self.EnterText.clear)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Chat telegram"))
Form.setToolTip(_translate("Form", "<html><head/><body><p>vd</p></body></html>"))
self.BUTTONpush.setText(_translate("Form", "Send Message"))
self.EnterText.setText(_translate("Form", "text"))
self.textEdit.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\';\">Proxy</span></p></body></html>"))
self.textEdit_2.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\';\">Port</span></p></body></html>"))
self.textEdit_3.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\';\">token</span></p></body></html>"))
self.textEdit_4.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\';\">chat_id</span></p></body></html>"))
Answer the question
In order to leave comments, you need to log in
Here is the code
def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
print(text)
QtWidgets.QMessageBox.critical(None, 'Error', text)
quit()
sys.excepthook = log_uncaught_exceptions
And may you be happy
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question