how to print continous data on pyqt5 text browser - python

I have created a manual web socket and I stucked.
Query) How to print continous/real time data receiving from server on text browser in pyqt5 GUI if connect (here name close) pushbutton is pressed (connection created) and if pushbutton is pressed again it should get toggled i.e. it should stop receiving data (connection close).
My code is
from PyQt5 import QtCore, QtGui, QtWidgets
from websocket import create_connection
class Ui_MainWindow(object):
def connect(self,MainWindow):
ws = create_connection("ws://192.168.0.205/ws")
self.textBrowser_2.append("Connection created")
while 1:
self.textBrowser_2.append(ws.recv())
print(ws.recv())
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(700, 70, 81, 61))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50, 0, 191, 51))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(30, 60, 81, 51))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(160, 130, 141, 81))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(20, 200, 201, 61))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(690, 260, 81, 51))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(20, 330, 251, 21))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(82, 70, 601, 61))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(20, 250, 651, 71))
self.lineEdit_2.setObjectName("lineEdit_2")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(260, 150, 381, 51))
self.textBrowser.setObjectName("textBrowser")
self.textBrowser_2 = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser_2.setGeometry(QtCore.QRect(30, 360, 731, 192))
self.textBrowser_2.setObjectName("textBrowser_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.pushButton.clicked.connect(self.connect)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Close"))
self.label.setText(_translate("MainWindow", "Server loaction"))
self.label_2.setText(_translate("MainWindow", "URL"))
self.label_3.setText(_translate("MainWindow", "Status :"))
self.label_4.setText(_translate("MainWindow", "Request"))
self.pushButton_2.setText(_translate("MainWindow", "Send"))
self.label_5.setText(_translate("MainWindow", "Message Log"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

First of all, do not modify the code generated by QtDesigner so to apply my solution you must regenerate the .py file and call it gui.py: pyuic5 filename.ui -o gui.py -x.
On the other hand, do not use the websocket module since it is designed for synchronous logic, in this case it is better to use the QtWebSockets module that allows you to interact with the websockets using the Qt eventloop.
import sys
from PyQt5 import QtCore, QtWidgets, QtWebSockets
from gui import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.socket = QtWebSockets.QWebSocket()
self.socket.textMessageReceived.connect(self.handle_text_message_received)
self.ui.pushButton.clicked.connect(self.connect_to_websocket)
def connect_to_websocket(self):
if self.socket.state() == QtNetwork.QAbstractSocket.UnconnectedState:
url = "ws://192.168.0.205/ws"
self.socket.open(QtCore.QUrl(url))
elif self.socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
self.socket.close()
def handle_text_message_received(self, message):
self.ui.textBrowser_2.append(message)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())

Related

I want to add a Viewbox to my code to make an AutoPan for X axis (pyqtgraph)

This is a GUI where I plot data from serial communication.
I want to add an AutoPan for my GUI but I don't know how.
I read there is an autopan in Viewbox but don't know how to implement it.
The option of Autopan is available when I launch the gui buy right clicking on the gui and selectign it manually but I want it to be enabled by default .
from PyQt5 import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
from random import randint
import serial
ser = serial.Serial('COM5',115200)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(769, 509)
MainWindow.setStyleSheet("\n""background-color: rgb(212, 212, 212);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.graphicsView = PlotWidget(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(80, 110, 561, 271))
self.graphicsView.setObjectName("graphicsView")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(260, 30, 211, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 10, 151, 80))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(650, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(650, 210, 121, 21))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(650, 140, 69, 22))
self.comboBox.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox.setEditable(False)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(650, 250, 69, 22))
self.comboBox_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox_2.setEditable(False)
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.splitter = QtWidgets.QSplitter(self.centralwidget)
self.splitter.setGeometry(QtCore.QRect(80, 410, 561, 51))
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.pushButton = QtWidgets.QPushButton(self.splitter)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color: rgb(255, 255, 210);")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.splitter)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_2.setFont(font)
self.pushButton_2.setStyleSheet("background-color: rgb(255, 255, 210);")
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 769, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.graphicsView.setBackground('w')
self.retranslateUi(MainWindow)
self.comboBox.setCurrentIndex(1)
self.comboBox_2.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Queen Monitor"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:18pt; font-weight:600;\">QUEEN MONITOR</span></p></body></html>"))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><img src=\":/rf/queen.png\"/></p></body></html>"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">Baud Rate</span></p></body></html>"))
self.label_4.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">Sampling Frequency</span></p></body></html>"))
self.comboBox.setItemText(0, _translate("MainWindow", "4800"))
self.comboBox.setItemText(1, _translate("MainWindow", "115200"))
self.comboBox_2.setItemText(0, _translate("MainWindow", ".... Hz"))
self.comboBox_2.setItemText(1, _translate("MainWindow", ".... Hz"))
self.comboBox_2.setItemText(2, _translate("MainWindow", ".... Hz"))
self.pushButton.setText(_translate("MainWindow", "START"))
self.pushButton_2.setText(_translate("MainWindow", "CLEAR"))
self.pushButton.clicked.connect(lambda:self.start())
self.pushButton_2.clicked.connect(lambda:self.clear())
self.x = [0]*2 # 100 time points
self.y = [0]*2
pen = pg.mkPen(color=(0, 0, 255))
self.data_line = self.graphicsView.plot(self.x, self.y, pen=pen)
def start(self):
self.timer = QtCore.QTimer()
self.timer.setInterval(1)
self.timer.timeout.connect(self.draw)
self.timer.start()
def draw(self):
"""#self.x = self.x[1:] # Remove the first y element.
self.x.append(self.x[-1] + 1) # Add a new value 1 higher than the last.
#self.y = self.y[1:] # Remove the first
self.y.append( randint(0,200)) # Add a new random value.
self.data_line.setData(self.x, self.y) # Update the data."""
rawData = ser.readline().decode("ascii")
dataSplitted = rawData.split(",")
dataSplitted.pop()
dataSplitted.pop(0)
for self.data_raw in dataSplitted:
self.x.append(self.x[-1] + 1)
self.y.append(int(self.data_raw))
self.data_line.setData(self.x, self.y)
def clear(self):
self.graphicsView.clear()
from pyqtgraph import PlotWidget
import rf_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Python YouTube downloader with pytube crashes when I search for video

I am making a YouTube video downloader with Python. I made the design with PyQt and edited the code in IDLE. Here is the code.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'YTD.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from pytube import YouTube
class Ui_MainWindow(object):
link = ''
video = None
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(354, 210)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
self.plainTextEdit.setGeometry(QtCore.QRect(10, 10, 261, 31))
self.plainTextEdit.setStyleSheet("font: 12pt \"MS Shell Dlg 2\";")
self.plainTextEdit.setPlainText("")
self.plainTextEdit.setObjectName("plainTextEdit")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(270, 10, 71, 31))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 80, 51, 21))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 99, 51, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 120, 51, 21))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(20, 140, 51, 21))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(80, 80, 251, 21))
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(80, 100, 251, 21))
self.label_6.setText("")
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(80, 120, 251, 21))
self.label_7.setText("")
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(80, 140, 251, 21))
self.label_8.setText("")
self.label_8.setObjectName("label_8")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(270, 160, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.pushButton.clicked.connect(self.on_search_clicked)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "SEARCH"))
self.label.setText(_translate("MainWindow", "Title:"))
self.label_2.setText(_translate("MainWindow", "Author:"))
self.label_3.setText(_translate("MainWindow", "Views:"))
self.label_4.setText(_translate("MainWindow", "Likes:"))
self.pushButton_2.setText(_translate("MainWindow", "Download"))
#THIS IS THE METHOD THAT I WROTE MYSELF
def on_search_clicked(self):
global link
link = self.plainTextEdit.toPlainText()
global video
video = YouTube(link)
self.label_5.setText(video.title)
self.label_6.setText(video.author)
self.label_7.setText(str(video.views))
self.label_8.setText(str(video.likes))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
The problem is, when I provide a link in the plainTextEdit box and press the pushButton, the application crashes. There must be some problem in on_search_clicked() as it is the only method I wrote and the rest is auto generated.

Cannot open second window, Event loop already running - PyQt5 [duplicate]

This question already has answers here:
Close and Open new Window PYQT5
(2 answers)
Closed 3 years ago.
I am currently trying to get a button press in one qt window to open a second window which is in another python file. My layout code was generated by converting a ui made in Qt designer to python.
My select feature code:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'movie_design.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import add_entry
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(597, 522)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(160, 40, 291, 51))
font = QtGui.QFont()
font.setPointSize(14)
font.setBold(False)
font.setUnderline(True)
font.setWeight(50)
font.setStrikeOut(False)
font.setKerning(True)
self.label.setFont(font)
self.label.setLineWidth(1)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(170, 110, 261, 91))
font = QtGui.QFont()
font.setPointSize(12)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(170, 230, 261, 91))
font = QtGui.QFont()
font.setPointSize(12)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(170, 350, 261, 91))
font = QtGui.QFont()
font.setPointSize(12)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 597, 26))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton_2.clicked.connect(self.add)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Movie Database Program"))
self.pushButton.setText(_translate("MainWindow", "Delete Record"))
self.pushButton_2.setText(_translate("MainWindow", "Add Record"))
self.pushButton_3.setText(_translate("MainWindow", "Search Records"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
def add(self):
add_entry.add_entry()
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
app.exec_()
if __name__ == "__main__":
main()
As you can see, I have created a button that when pressed calls the function in the program "add_entry.py"
Add entry.py code:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'add_entry.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(555, 418)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 30, 533, 28))
font = QtGui.QFont()
font.setPointSize(14)
self.label.setFont(font)
self.label.setTextFormat(QtCore.Qt.AutoText)
self.label.setScaledContents(False)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.formLayoutWidget = QtWidgets.QWidget(Dialog)
self.formLayoutWidget.setGeometry(QtCore.QRect(30, 70, 501, 321))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.formLayout.setObjectName("formLayout")
self.label_2 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_2)
self.MovieTitle = QtWidgets.QLineEdit(self.formLayoutWidget)
self.MovieTitle.setObjectName("MovieTitle")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.MovieTitle)
self.label_3 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_3)
self.MovieStudio = QtWidgets.QLineEdit(self.formLayoutWidget)
self.MovieStudio.setObjectName("MovieStudio")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.MovieStudio)
self.label_4 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_4)
self.dateEdit = QtWidgets.QDateEdit(self.formLayoutWidget)
self.dateEdit.setObjectName("dateEdit")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.dateEdit)
self.label_5 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_5)
self.ProductionCost = QtWidgets.QSpinBox(self.formLayoutWidget)
self.ProductionCost.setMaximum(1000000000)
self.ProductionCost.setObjectName("ProductionCost")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.ProductionCost)
self.label_6 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_6)
self.BoxOfficeRevenue = QtWidgets.QSpinBox(self.formLayoutWidget)
self.BoxOfficeRevenue.setMaximum(1000000000)
self.BoxOfficeRevenue.setObjectName("BoxOfficeRevenue")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.BoxOfficeRevenue)
self.label_7 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_7.setFont(font)
self.label_7.setObjectName("label_7")
self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.label_7)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.No = QtWidgets.QRadioButton(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(10)
self.No.setFont(font)
self.No.setObjectName("No")
self.horizontalLayout.addWidget(self.No)
self.Yes = QtWidgets.QRadioButton(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(10)
self.Yes.setFont(font)
self.Yes.setObjectName("Yes")
self.horizontalLayout.addWidget(self.Yes)
self.formLayout.setLayout(5, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout)
self.label_8 = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_8.setFont(font)
self.label_8.setObjectName("label_8")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.label_8)
self.classificationBox = QtWidgets.QComboBox(self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(10)
self.classificationBox.setFont(font)
self.classificationBox.setObjectName("classificationBox")
self.classificationBox.addItem("")
self.classificationBox.addItem("")
self.classificationBox.addItem("")
self.classificationBox.addItem("")
self.classificationBox.addItem("")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.classificationBox)
self.pushButton = QtWidgets.QPushButton(self.formLayoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setObjectName("pushButton")
self.formLayout.setWidget(7, QtWidgets.QFormLayout.SpanningRole, self.pushButton)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "<html><head/><body><p><span style=\" font-size:12pt; text-decoration: underline;\">Add Entry</span></p></body></html>"))
self.label_2.setText(_translate("Dialog", "Movie Title"))
self.label_3.setText(_translate("Dialog", "Movie Studio"))
self.label_4.setText(_translate("Dialog", "Release Date"))
self.label_5.setText(_translate("Dialog", "Production Cost (m$)"))
self.label_6.setText(_translate("Dialog", "Box Office Revenue (m$)"))
self.label_7.setText(_translate("Dialog", "Have you seen this movie?"))
self.No.setText(_translate("Dialog", "Yes"))
self.Yes.setText(_translate("Dialog", "No"))
self.label_8.setText(_translate("Dialog", "Classification (Age Rating)"))
self.classificationBox.setItemText(0, _translate("Dialog", "U"))
self.classificationBox.setItemText(1, _translate("Dialog", "PG"))
self.classificationBox.setItemText(2, _translate("Dialog", "12"))
self.classificationBox.setItemText(3, _translate("Dialog", "15"))
self.classificationBox.setItemText(4, _translate("Dialog", "18"))
self.pushButton.setText(_translate("Dialog", "Add Entry"))
def add_entry():
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
app.exec_()
if __name__ == "__main__":
add_entry()
The issue is that the when the button is pressed, the program crashes, telling me that "Event loop already running". How do I fix this?
Qt, like many GUI frameworks, is based on an event loop which is started with app.exec_() and then waits for events to react to (both from the user or the system).
For each Qt program there should always be a single and only QApplication instance running its event loop.
With your implementation, each time you press the button, you're trying to create and launch a new QApplication, and Qt will not allow you for the reason above.
Nonetheless, the problem with your code is somewhere else, as you are using the generated UI code in the wrong way: those files should never be used as a basis to create your program code (in fact, you should always leave them as they are).
I suggest you to carefully read the official documentation about using Designer to understand how to use those files.
Regenerate the UI files with pyuic, and then create a new script that will probably contain something similar to this:
from PyQt5 import QtWidgets
from ui_mainwindow import Ui_MainWindow
from ui_dialog import Ui_Dialog
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton_2.clicked.connect(self.add)
def add(self):
dialog = Dialog(self)
dialog.exec_()
class Dialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
In this example I used the third method (multiple inheritance approach) explained in the documentation given above.

implementing buttons' functions on main instead on script from pyqt5

I created a GUI using Qt designer, and converted it into .py file.
I used to write the functions directly in the GUI .py file, but I've been told to separate the code into two files: one with only the GUI commands as been converted from Qt designer, and Main - that would work all of the buttons and widgets of the GUI.
Now, I've managed to import the GUI from different file, and when I run the script the GUI does come up, but when I try to write functions I seem to have troubles.
This is my main:
from PyQt5 import QtWidgets
from mainwin import Ui_MainWindow
import sys
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
super(ApplicationWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.exitbtn.clicked.connect(self.exitclicked) ***this is the connection and function that I'm trying to make 'em work***
def exitclicked(self,Dialog):
sys.exit()
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
application = ApplicationWindow()
application.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
And I don't know if it's relevant, but this is my GUI converted from Qt designer.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(895, 422)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.txtoutput = QtWidgets.QTextBrowser(self.centralwidget)
self.txtoutput.setGeometry(QtCore.QRect(150, 200, 471, 192))
self.txtoutput.setObjectName("txtoutput")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(50, 90, 69, 22))
self.comboBox.setObjectName("comboBox")
self.lbl = QtWidgets.QLabel(self.centralwidget)
self.lbl.setGeometry(QtCore.QRect(90, 30, 81, 16))
self.lbl.setObjectName("lbl")
self.lcdNumber = QtWidgets.QLCDNumber(self.centralwidget)
self.lcdNumber.setGeometry(QtCore.QRect(340, 170, 151, 23))
self.lcdNumber.setObjectName("lcdNumber")
self.getserialbtn = QtWidgets.QPushButton(self.centralwidget)
self.getserialbtn.setGeometry(QtCore.QRect(210, 50, 75, 23))
self.getserialbtn.setObjectName("getserialbtn")
self.chuckrealeasebtn = QtWidgets.QPushButton(self.centralwidget)
self.chuckrealeasebtn.setGeometry(QtCore.QRect(50, 120, 75, 23))
self.chuckrealeasebtn.setObjectName("chuckrealeasebtn")
self.runbtn = QtWidgets.QPushButton(self.centralwidget)
self.runbtn.setGeometry(QtCore.QRect(580, 70, 91, 61))
font = QtGui.QFont()
font.setPointSize(28)
font.setBold(True)
font.setWeight(75)
self.runbtn.setFont(font)
self.runbtn.setCheckable(False)
self.runbtn.setObjectName("runbtn")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(50, 50, 151, 31))
self.textEdit.setObjectName("textEdit")
self.stopbtn = QtWidgets.QPushButton(self.centralwidget)
self.stopbtn.setGeometry(QtCore.QRect(680, 70, 91, 61))
font = QtGui.QFont()
font.setPointSize(28)
font.setBold(True)
font.setWeight(75)
self.stopbtn.setFont(font)
self.stopbtn.setObjectName("stopbtn")
self.exitbtn = QtWidgets.QPushButton(self.centralwidget)
self.exitbtn.setGeometry(QtCore.QRect(740, 370, 75, 23))
self.exitbtn.setObjectName("exitbtn")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.lbl.setText(_translate("MainWindow", "Enter serial #"))
self.getserialbtn.setText(_translate("MainWindow", "Enter"))
self.chuckrealeasebtn.setText(_translate("MainWindow", "chuck"))
self.runbtn.setText(_translate("MainWindow", "Run"))
self.stopbtn.setText(_translate("MainWindow", "Stop"))
self.exitbtn.setText(_translate("MainWindow", "Exit"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
The error that I get when I try to run it is:
AttributeError: 'ApplicationWindow' object has no attribute 'exitbtn'
Would love if someone can write the right syntax to be able to implement functions through main.
Thank you so much :D
Try it:
main.py
from PyQt5 import QtWidgets
from mainwin import Ui_MainWindow
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
super(ApplicationWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# self.exitbtn.clicked.connect(self.exitclicked)
self.ui.exitbtn.clicked.connect(self.exitclicked) # +
def exitclicked(self): # +
self.close() # +
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
application = ApplicationWindow()
application.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
mainwin.py
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(895, 422)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.txtoutput = QtWidgets.QTextBrowser(self.centralwidget)
self.txtoutput.setGeometry(QtCore.QRect(150, 200, 471, 192))
self.txtoutput.setObjectName("txtoutput")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(50, 90, 69, 22))
self.comboBox.setObjectName("comboBox")
self.lbl = QtWidgets.QLabel(self.centralwidget)
self.lbl.setGeometry(QtCore.QRect(90, 30, 81, 16))
self.lbl.setObjectName("lbl")
self.lcdNumber = QtWidgets.QLCDNumber(self.centralwidget)
self.lcdNumber.setGeometry(QtCore.QRect(340, 170, 151, 23))
self.lcdNumber.setObjectName("lcdNumber")
self.getserialbtn = QtWidgets.QPushButton(self.centralwidget)
self.getserialbtn.setGeometry(QtCore.QRect(210, 50, 75, 23))
self.getserialbtn.setObjectName("getserialbtn")
self.chuckrealeasebtn = QtWidgets.QPushButton(self.centralwidget)
self.chuckrealeasebtn.setGeometry(QtCore.QRect(50, 120, 75, 23))
self.chuckrealeasebtn.setObjectName("chuckrealeasebtn")
self.runbtn = QtWidgets.QPushButton(self.centralwidget)
self.runbtn.setGeometry(QtCore.QRect(580, 70, 91, 61))
font = QtGui.QFont()
font.setPointSize(28)
font.setBold(True)
font.setWeight(75)
self.runbtn.setFont(font)
self.runbtn.setCheckable(False)
self.runbtn.setObjectName("runbtn")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(50, 50, 151, 31))
self.textEdit.setObjectName("textEdit")
self.stopbtn = QtWidgets.QPushButton(self.centralwidget)
self.stopbtn.setGeometry(QtCore.QRect(680, 70, 91, 61))
font = QtGui.QFont()
font.setPointSize(28)
font.setBold(True)
font.setWeight(75)
self.stopbtn.setFont(font)
self.stopbtn.setObjectName("stopbtn")
self.exitbtn = QtWidgets.QPushButton(self.centralwidget)
self.exitbtn.setGeometry(QtCore.QRect(740, 370, 75, 23))
self.exitbtn.setObjectName("exitbtn")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.lbl.setText(_translate("MainWindow", "Enter serial #"))
self.getserialbtn.setText(_translate("MainWindow", "Enter"))
self.chuckrealeasebtn.setText(_translate("MainWindow", "chuck"))
self.runbtn.setText(_translate("MainWindow", "Run"))
self.stopbtn.setText(_translate("MainWindow", "Stop"))
self.exitbtn.setText(_translate("MainWindow", "Exit"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

i dont know how to take input in one textbox and show show output in other textbox

I don't know how to take input of user in one textbox and show output in other textbox.
I tried but it's not working.
from PyQt5 import QtCore, QtGui, QtWidgets
import os
def click(self):
self.pushButton.click()
print("hello")
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(664, 389)
MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
MainWindow.setLayoutDirection(QtCore.Qt.LeftToRight)
MainWindow.setAutoFillBackground(False)
MainWindow.setStyleSheet("background-image: url(:/background/White-Marble-Background-product-Photography-backdrops-Newborn-Photo-props-baby-shower-PhotoCall-pictures-newborn-propsXt-6735.jpg_640x640.webp);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(20, 20, 621, 51))
font = QtGui.QFont()
font.setFamily("Yu Gothic UI Semibold")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.lineEdit.setFont(font)
self.lineEdit.setAutoFillBackground(False)
self.lineEdit.setObjectName("lineEdit")
inp_val = self.lineEdit.text()
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(240, 290, 151, 41))
font = QtGui.QFont()
font.setFamily("Rubik")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color: rgb(240, 184, 160);")
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(click(self))
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(20, 90, 621, 191))
font = QtGui.QFont()
font.setFamily("Yu Gothic UI Semibold")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.textEdit.setFont(font)
self.textEdit.setCursorWidth(2)
self.textEdit.setObjectName("textEdit")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Rahul"))
self.pushButton.setText(_translate("MainWindow", "Run"))
self.lineEdit.setPlaceholderText(_translate("MainWindow", "Type Your Text Here....."))
self.textEdit.setPlaceholderText(_translate("MainWindow", "Your Output....."))
import test2_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
How do I input in lineedit and show output in textedit?
Try it:
from PyQt5 import QtCore, QtGui, QtWidgets
# ? import os
#def click(self):
# self.pushButton.click()
# print("hello")
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(664, 389)
MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
MainWindow.setLayoutDirection(QtCore.Qt.LeftToRight)
MainWindow.setAutoFillBackground(False)
MainWindow.setStyleSheet("background-image: url(:/background/White-Marble-Background-product-Photography-backdrops-Newborn-Photo-props-baby-shower-PhotoCall-pictures-newborn-propsXt-6735.jpg_640x640.webp);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(20, 20, 621, 51))
font = QtGui.QFont()
font.setFamily("Yu Gothic UI Semibold")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.lineEdit.setFont(font)
self.lineEdit.setAutoFillBackground(False)
self.lineEdit.setObjectName("lineEdit")
inp_val = self.lineEdit.text()
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(240, 290, 151, 41))
font = QtGui.QFont()
font.setFamily("Rubik")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color: rgb(240, 184, 160);")
self.pushButton.setObjectName("pushButton")
# self.pushButton.clicked.connect(click(self))
self.pushButton.clicked.connect(self.onClick)
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(20, 90, 621, 191))
font = QtGui.QFont()
font.setFamily("Yu Gothic UI Semibold")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.textEdit.setFont(font)
self.textEdit.setCursorWidth(2)
self.textEdit.setObjectName("textEdit")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def onClick(self):
# self.pushButton.click()
print("hello")
self.textEdit.append(self.lineEdit.text()) # <---
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Rahul"))
self.pushButton.setText(_translate("MainWindow", "Run"))
self.lineEdit.setPlaceholderText(_translate("MainWindow", "Type Your Text Here....."))
self.textEdit.setPlaceholderText(_translate("MainWindow", "Your Output....."))
# ? import test2_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Use setPlainText:
def click(self):
inputtext = self.lineEdit.text()
self.textEdit.setPlainText(inputtext)
Also you need to put function click inside class Ui_MainWindow, like this:
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
#your code
def click(self):
inputtext = self.lineEdit.text()
self.textEdit.setPlainText(inputtext)
Also call function click like:
self.pushButton.clicked.connect(self.click)

Categories