Related
I have designed a UI in QT Designer and successfully converted into Python code as well. It is executing fine in PyCharm window.
However, I want to capture the inputs in each widget into a file and am stuck without any luck.
# Form implementation generated from reading ui file 'Pre_Sales_1.ui'
#
# Created by: PyQt6 UI code generator 6.2.3
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1116, 718)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.frame1 = QtWidgets.QFrame(self.centralwidget)
self.frame1.setGeometry(QtCore.QRect(10, 20, 361, 161))
self.frame1.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame1.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame1.setObjectName("frame1")
self.label_2 = QtWidgets.QLabel(self.frame1)
self.label_2.setGeometry(QtCore.QRect(0, 10, 131, 31))
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(self.frame1)
self.lineEdit.setGeometry(QtCore.QRect(140, 10, 221, 22))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setPlaceholderText("Please Enter the name of the Customer")
self.label_3 = QtWidgets.QLabel(self.frame1)
self.label_3.setGeometry(QtCore.QRect(0, 50, 131, 31))
self.label_3.setObjectName("label_3")
self.textEdit = QtWidgets.QTextEdit(self.frame1)
self.textEdit.setGeometry(QtCore.QRect(140, 40, 221, 111))
self.textEdit.setObjectName("textEdit")
self.textEdit.setPlaceholderText("Please Enter the Primary Address of the Customer")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(500, 0, 231, 16))
self.label.setObjectName("label")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(390, 20, 371, 161))
self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame.setObjectName("frame")
self.label_4 = QtWidgets.QLabel(self.frame)
self.label_4.setGeometry(QtCore.QRect(0, 10, 141, 20))
self.label_4.setObjectName("label_4")
self.lineEdit_2 = QtWidgets.QLineEdit(self.frame)
self.lineEdit_2.setGeometry(QtCore.QRect(140, 10, 221, 22))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.frame)
self.lineEdit_3.setGeometry(QtCore.QRect(140, 50, 221, 22))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.frame)
self.lineEdit_4.setGeometry(QtCore.QRect(140, 130, 221, 22))
self.lineEdit_4.setObjectName("lineEdit_4")
self.label_5 = QtWidgets.QLabel(self.frame)
self.label_5.setGeometry(QtCore.QRect(0, 50, 141, 20))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.frame)
self.label_6.setGeometry(QtCore.QRect(0, 90, 141, 20))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.frame)
self.label_7.setGeometry(QtCore.QRect(0, 130, 141, 20))
self.label_7.setObjectName("label_7")
self.lineEdit_5 = QtWidgets.QLineEdit(self.frame)
self.lineEdit_5.setGeometry(QtCore.QRect(140, 90, 221, 22))
self.lineEdit_5.setObjectName("lineEdit_5")
self.calendarWidget = QtWidgets.QCalendarWidget(self.centralwidget)
self.calendarWidget.setGeometry(QtCore.QRect(760, 20, 351, 151))
self.calendarWidget.setObjectName("calendarWidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(0, 190, 1111, 441))
self.tabWidget.setAutoFillBackground(False)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.frame_2 = QtWidgets.QFrame(self.tab)
self.frame_2.setGeometry(QtCore.QRect(0, 20, 201, 80))
self.frame_2.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_2.setObjectName("frame_2")
self.label_8 = QtWidgets.QLabel(self.frame_2)
self.label_8.setGeometry(QtCore.QRect(10, 0, 111, 16))
self.label_8.setObjectName("label_8")
self.checkBox = QtWidgets.QCheckBox(self.frame_2)
self.checkBox.setGeometry(QtCore.QRect(10, 30, 181, 20))
self.checkBox.setTristate(False)
self.checkBox.setObjectName("checkBox")
self.checkBox_2 = QtWidgets.QCheckBox(self.frame_2)
self.checkBox_2.setGeometry(QtCore.QRect(10, 60, 181, 20))
self.checkBox_2.setObjectName("checkBox_2")
self.frame_3 = QtWidgets.QFrame(self.frame_2)
self.frame_3.setGeometry(QtCore.QRect(200, 50, 201, 80))
self.frame_3.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_3.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_3.setObjectName("frame_3")
self.label_9 = QtWidgets.QLabel(self.frame_3)
self.label_9.setGeometry(QtCore.QRect(10, 0, 111, 16))
self.label_9.setObjectName("label_9")
self.checkBox_3 = QtWidgets.QCheckBox(self.frame_3)
self.checkBox_3.setGeometry(QtCore.QRect(10, 20, 181, 20))
self.checkBox_3.setTristate(False)
self.checkBox_3.setObjectName("checkBox_3")
self.checkBox_4 = QtWidgets.QCheckBox(self.frame_3)
self.checkBox_4.setGeometry(QtCore.QRect(10, 40, 181, 20))
self.checkBox_4.setObjectName("checkBox_4")
self.frame_4 = QtWidgets.QFrame(self.frame_2)
self.frame_4.setGeometry(QtCore.QRect(200, 40, 201, 80))
self.frame_4.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_4.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_4.setObjectName("frame_4")
self.label_10 = QtWidgets.QLabel(self.frame_4)
self.label_10.setGeometry(QtCore.QRect(10, 0, 111, 16))
self.label_10.setObjectName("label_10")
self.checkBox_5 = QtWidgets.QCheckBox(self.frame_4)
self.checkBox_5.setGeometry(QtCore.QRect(10, 20, 181, 20))
self.checkBox_5.setTristate(False)
self.checkBox_5.setObjectName("checkBox_5")
self.checkBox_6 = QtWidgets.QCheckBox(self.frame_4)
self.checkBox_6.setGeometry(QtCore.QRect(10, 40, 181, 20))
self.checkBox_6.setObjectName("checkBox_6")
self.frame_5 = QtWidgets.QFrame(self.frame_4)
self.frame_5.setGeometry(QtCore.QRect(200, 50, 201, 80))
self.frame_5.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_5.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_5.setObjectName("frame_5")
self.label_11 = QtWidgets.QLabel(self.frame_5)
self.label_11.setGeometry(QtCore.QRect(10, 0, 111, 16))
self.label_11.setObjectName("label_11")
self.checkBox_7 = QtWidgets.QCheckBox(self.frame_5)
self.checkBox_7.setGeometry(QtCore.QRect(10, 20, 181, 20))
self.checkBox_7.setTristate(False)
self.checkBox_7.setObjectName("checkBox_7")
self.checkBox_8 = QtWidgets.QCheckBox(self.frame_5)
self.checkBox_8.setGeometry(QtCore.QRect(10, 40, 181, 20))
self.checkBox_8.setObjectName("checkBox_8")
self.frame_6 = QtWidgets.QFrame(self.tab)
self.frame_6.setGeometry(QtCore.QRect(210, 20, 611, 91))
self.frame_6.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_6.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_6.setObjectName("frame_6")
self.label_12 = QtWidgets.QLabel(self.frame_6)
self.label_12.setGeometry(QtCore.QRect(270, 0, 101, 16))
self.label_12.setObjectName("label_12")
self.label_13 = QtWidgets.QLabel(self.frame_6)
self.label_13.setGeometry(QtCore.QRect(10, 20, 51, 21))
self.label_13.setObjectName("label_13")
self.label_14 = QtWidgets.QLabel(self.frame_6)
self.label_14.setGeometry(QtCore.QRect(0, 60, 61, 21))
self.label_14.setObjectName("label_14")
self.comboBox = QtWidgets.QComboBox(self.frame_6)
self.comboBox.setGeometry(QtCore.QRect(60, 20, 221, 22))
self.comboBox.setObjectName("comboBox")
self.comboBox_2 = QtWidgets.QComboBox(self.frame_6)
self.comboBox_2.setGeometry(QtCore.QRect(60, 60, 221, 22))
self.comboBox_2.setObjectName("comboBox_2")
self.label_15 = QtWidgets.QLabel(self.frame_6)
self.label_15.setGeometry(QtCore.QRect(290, 20, 101, 21))
self.label_15.setObjectName("label_15")
self.comboBox_3 = QtWidgets.QComboBox(self.frame_6)
self.comboBox_3.setGeometry(QtCore.QRect(390, 20, 221, 22))
self.comboBox_3.setObjectName("comboBox_3")
self.comboBox_4 = QtWidgets.QComboBox(self.frame_6)
self.comboBox_4.setGeometry(QtCore.QRect(390, 60, 221, 22))
self.comboBox_4.setObjectName("comboBox_4")
self.label_16 = QtWidgets.QLabel(self.frame_6)
self.label_16.setGeometry(QtCore.QRect(310, 60, 71, 21))
self.label_16.setObjectName("label_16")
self.frame_7 = QtWidgets.QFrame(self.frame_6)
self.frame_7.setGeometry(QtCore.QRect(0, 0, 611, 91))
self.frame_7.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_7.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_7.setObjectName("frame_7")
self.label_18 = QtWidgets.QLabel(self.frame_7)
self.label_18.setGeometry(QtCore.QRect(270, 0, 101, 16))
self.label_18.setObjectName("label_18")
self.label_19 = QtWidgets.QLabel(self.frame_7)
self.label_19.setGeometry(QtCore.QRect(10, 20, 51, 21))
self.label_19.setObjectName("label_19")
self.label_20 = QtWidgets.QLabel(self.frame_7)
self.label_20.setGeometry(QtCore.QRect(0, 60, 61, 21))
self.label_20.setObjectName("label_20")
self.comboBox_5 = QtWidgets.QComboBox(self.frame_7)
self.comboBox_5.setGeometry(QtCore.QRect(60, 20, 221, 22))
self.comboBox_5.setObjectName("comboBox_5")
self.comboBox_5.addItems(["Discrete Manufacturing","Chemicals"])
self.comboBox_6 = QtWidgets.QComboBox(self.frame_7)
self.comboBox_6.setGeometry(QtCore.QRect(60, 60, 221, 22))
self.comboBox_6.setObjectName("comboBox_6")
self.label_21 = QtWidgets.QLabel(self.frame_7)
self.label_21.setGeometry(QtCore.QRect(290, 20, 101, 21))
self.label_21.setObjectName("label_21")
self.comboBox_7 = QtWidgets.QComboBox(self.frame_7)
self.comboBox_7.setGeometry(QtCore.QRect(390, 20, 221, 22))
self.comboBox_7.setObjectName("comboBox_7")
self.comboBox_8 = QtWidgets.QComboBox(self.frame_7)
self.comboBox_8.setGeometry(QtCore.QRect(390, 60, 221, 22))
self.comboBox_8.setObjectName("comboBox_8")
self.label_22 = QtWidgets.QLabel(self.frame_7)
self.label_22.setGeometry(QtCore.QRect(310, 60, 71, 21))
self.label_22.setObjectName("label_22")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(0, 0, 1101, 111))
self.groupBox.setObjectName("groupBox")
self.frame_8 = QtWidgets.QFrame(self.groupBox)
self.frame_8.setGeometry(QtCore.QRect(830, 19, 271, 91))
self.frame_8.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame_8.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame_8.setObjectName("frame_8")
self.label_17 = QtWidgets.QLabel(self.frame_8)
self.label_17.setGeometry(QtCore.QRect(90, 0, 101, 16))
self.label_17.setObjectName("label_17")
self.textEdit_2 = QtWidgets.QTextEdit(self.frame_8)
self.textEdit_2.setGeometry(QtCore.QRect(0, 20, 271, 71))
self.textEdit_2.setObjectName("textEdit_2")
self.groupBox.raise_()
self.frame_2.raise_()
self.frame_6.raise_()
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.tabWidget.addTab(self.tab_2, "")
self.tab_3 = QtWidgets.QWidget()
self.tab_3.setObjectName("tab_3")
self.tabWidget.addTab(self.tab_3, "")
self.tab_4 = QtWidgets.QWidget()
self.tab_4.setObjectName("tab_4")
self.tabWidget.addTab(self.tab_4, "")
self.tab_5 = QtWidgets.QWidget()
self.tab_5.setObjectName("tab_5")
self.tabWidget.addTab(self.tab_5, "")
self.tab_6 = QtWidgets.QWidget()
self.tab_6.setObjectName("tab_6")
self.tabWidget.addTab(self.tab_6, "")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(1000, 640, 93, 28))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1116, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Welcome to KOVI Pre-Sales"))
self.label_2.setText(_translate("MainWindow", "Name of the Customer"))
self.label_3.setText(_translate("MainWindow", "Primary Address "))
self.label.setText(_translate("MainWindow", "Please Enter Customer Information"))
self.label_4.setText(_translate("MainWindow", "Primay Contact Person"))
self.label_5.setText(_translate("MainWindow", "Primay Contact Number"))
self.label_6.setText(_translate("MainWindow", "Mobile Number"))
self.label_7.setText(_translate("MainWindow", "Work Email ID"))
self.label_8.setText(_translate("MainWindow", "Opportunity Details"))
self.checkBox.setText(_translate("MainWindow", "Net New Implementation"))
self.checkBox_2.setText(_translate("MainWindow", "New Plant Roll-Out"))
self.label_9.setText(_translate("MainWindow", "Opportunity Details"))
self.checkBox_3.setText(_translate("MainWindow", "Net New Implementation"))
self.checkBox_4.setText(_translate("MainWindow", "New Plant Roll-Out"))
self.label_10.setText(_translate("MainWindow", "Opportunity Details"))
self.checkBox_5.setText(_translate("MainWindow", "Net New Implementation"))
self.checkBox_6.setText(_translate("MainWindow", "New Plant Roll-Out"))
self.label_11.setText(_translate("MainWindow", "Opportunity Details"))
self.checkBox_7.setText(_translate("MainWindow", "Net New Implementation"))
self.checkBox_8.setText(_translate("MainWindow", "New Plant Roll-Out"))
self.label_12.setText(_translate("MainWindow", "Business Details"))
self.label_13.setText(_translate("MainWindow", "Industry"))
self.label_14.setText(_translate("MainWindow", "Geography"))
self.label_15.setText(_translate("MainWindow", "Annual Business"))
self.label_16.setText(_translate("MainWindow", "Existing ERP"))
self.label_18.setText(_translate("MainWindow", "Business Details"))
self.label_19.setText(_translate("MainWindow", "Industry"))
self.label_20.setText(_translate("MainWindow", "Geography"))
self.label_21.setText(_translate("MainWindow", "Annual Business"))
self.label_22.setText(_translate("MainWindow", "Existing ERP"))
self.groupBox.setTitle(_translate("MainWindow", "Basic Details about Business of the Customer"))
self.label_17.setText(_translate("MainWindow", "Other Details"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Implementation"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "OS/DB Migration"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "S/4HANA_Conversion"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "DC2Cloud Migration"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_5), _translate("MainWindow", "Upgrade"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_6), _translate("MainWindow", "Application Maintenance Service"))
self.pushButton.setText(_translate("MainWindow", "Submit"))
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 created a calculator for the Pythagorean Theorem with python and decided I should make a GUI for it.
I wanted something where I could drag and drop the GUI as I have tried Tkinter before and it is really hard. I created a GUI with QT designer and then started to code the buttons, but for some reason, it wasn't working with Pycharm I got the error ImportError: DLL load failed: The specified module could not be found every time I ran the code, so if you can fix that please reply. When I tried to run it in MU text editor it worked fine. So I started coding the buttons to do something, but when I run the code the window is empty. Please Help. Thanks, Famous8. This is my first post :)
The Code:
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow,)
from PyQt5 import QtWidgets
import PTCGUI
class MainWindow:
def __init__(self):
self.main_win = QMainWindow()
self.ui = PTCGUI()
self.ui.setupUi(self.main_win)
self.ui.stackedWidget.setCurrentWidget(self.ui.home)
self.ui.pushButton.clicked.connect(self.sqrnum)
self.ui.pushButton_4.clicked.connect(self.sqrtnum)
self.ui.pushButton_3.clicked.connect(self.addnum)
self.ui.pushButton_2.clicked.connect(self.sidea)
self.ui.pushButton_5.clicked.connect(self.sideb)
self.ui.pushButton_6.clicked.connect(self.sidec)
self.ui.pushButton_7.clicked.connect(self.dettri)
self.ui.pushButton_8.clicked.connect(self.settings)
def show(self):
self.main_win.show()
def sqrnum(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.Square)
def sqrtnum(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.sqrt)
def addnum(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.add)
def sidea(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.sidea)
def sideb(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.sideb)
def sidec(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.sidec)
def dettri(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.righttriangle)
def settings(self):
self.ui.stackedWidget.setCurrentWidget(self.ui.Settings)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
MainWindow.show()
sys.exit(app.exec_())
Also here is the contents of PTCGUI, the file with all the info
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(939, 606)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(30, 460, 131, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(450, 460, 131, 41))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(310, 460, 131, 41))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(170, 460, 131, 41))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(590, 460, 131, 41))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_6.setGeometry(QtCore.QRect(730, 460, 131, 41))
self.pushButton_6.setObjectName("pushButton_6")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(740, 560, 191, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 560, 91, 16))
self.label_3.setObjectName("label_3")
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_7.setGeometry(QtCore.QRect(30, 510, 131, 41))
self.pushButton_7.setObjectName("pushButton_7")
self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
self.stackedWidget.setGeometry(QtCore.QRect(30, 40, 871, 401))
self.stackedWidget.setObjectName("stackedWidget")
self.sideb = QtWidgets.QWidget()
self.sideb.setObjectName("sideb")
self.lineEdit_25 = QtWidgets.QLineEdit(self.sideb)
self.lineEdit_25.setGeometry(QtCore.QRect(200, 330, 81, 31))
self.lineEdit_25.setObjectName("lineEdit_25")
self.lineEdit_26 = QtWidgets.QLineEdit(self.sideb)
self.lineEdit_26.setGeometry(QtCore.QRect(110, 330, 81, 31))
self.lineEdit_26.setObjectName("lineEdit_26")
self.lineEdit_27 = QtWidgets.QLineEdit(self.sideb)
self.lineEdit_27.setGeometry(QtCore.QRect(20, 330, 81, 31))
self.lineEdit_27.setObjectName("lineEdit_27")
self.pushButton_23 = QtWidgets.QPushButton(self.sideb)
self.pushButton_23.setGeometry(QtCore.QRect(120, 360, 61, 23))
self.pushButton_23.setObjectName("pushButton_23")
self.pushButton_24 = QtWidgets.QPushButton(self.sideb)
self.pushButton_24.setGeometry(QtCore.QRect(30, 360, 61, 23))
self.pushButton_24.setObjectName("pushButton_24")
self.label_9 = QtWidgets.QLabel(self.sideb)
self.label_9.setGeometry(QtCore.QRect(0, 310, 101, 16))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(self.sideb)
self.label_10.setGeometry(QtCore.QRect(110, 310, 101, 16))
self.label_10.setObjectName("label_10")
self.stackedWidget.addWidget(self.sideb)
self.sidec = QtWidgets.QWidget()
self.sidec.setObjectName("sidec")
self.lineEdit_28 = QtWidgets.QLineEdit(self.sidec)
self.lineEdit_28.setGeometry(QtCore.QRect(20, 330, 81, 31))
self.lineEdit_28.setObjectName("lineEdit_28")
self.lineEdit_29 = QtWidgets.QLineEdit(self.sidec)
self.lineEdit_29.setGeometry(QtCore.QRect(110, 330, 81, 31))
self.lineEdit_29.setObjectName("lineEdit_29")
self.lineEdit_30 = QtWidgets.QLineEdit(self.sidec)
self.lineEdit_30.setGeometry(QtCore.QRect(200, 330, 81, 31))
self.lineEdit_30.setObjectName("lineEdit_30")
self.pushButton_25 = QtWidgets.QPushButton(self.sidec)
self.pushButton_25.setGeometry(QtCore.QRect(30, 360, 61, 23))
self.pushButton_25.setObjectName("pushButton_25")
self.pushButton_26 = QtWidgets.QPushButton(self.sidec)
self.pushButton_26.setGeometry(QtCore.QRect(120, 360, 61, 23))
self.pushButton_26.setObjectName("pushButton_26")
self.label_11 = QtWidgets.QLabel(self.sidec)
self.label_11.setGeometry(QtCore.QRect(110, 310, 101, 16))
self.label_11.setObjectName("label_11")
self.label_14 = QtWidgets.QLabel(self.sidec)
self.label_14.setGeometry(QtCore.QRect(10, 310, 101, 16))
self.label_14.setObjectName("label_14")
self.stackedWidget.addWidget(self.sidec)
self.righttriangle = QtWidgets.QWidget()
self.righttriangle.setObjectName("righttriangle")
self.lineEdit_31 = QtWidgets.QLineEdit(self.righttriangle)
self.lineEdit_31.setGeometry(QtCore.QRect(30, 350, 81, 31))
self.lineEdit_31.setObjectName("lineEdit_31")
self.lineEdit_32 = QtWidgets.QLineEdit(self.righttriangle)
self.lineEdit_32.setGeometry(QtCore.QRect(160, 350, 81, 31))
self.lineEdit_32.setObjectName("lineEdit_32")
self.lineEdit_33 = QtWidgets.QLineEdit(self.righttriangle)
self.lineEdit_33.setGeometry(QtCore.QRect(280, 350, 81, 31))
self.lineEdit_33.setObjectName("lineEdit_33")
self.lineEdit_34 = QtWidgets.QLineEdit(self.righttriangle)
self.lineEdit_34.setGeometry(QtCore.QRect(390, 350, 161, 31))
self.lineEdit_34.setObjectName("lineEdit_34")
self.label_15 = QtWidgets.QLabel(self.righttriangle)
self.label_15.setGeometry(QtCore.QRect(150, 330, 101, 16))
self.label_15.setObjectName("label_15")
self.label_16 = QtWidgets.QLabel(self.righttriangle)
self.label_16.setGeometry(QtCore.QRect(270, 330, 101, 16))
self.label_16.setObjectName("label_16")
self.label_17 = QtWidgets.QLabel(self.righttriangle)
self.label_17.setGeometry(QtCore.QRect(20, 330, 101, 16))
self.label_17.setObjectName("label_17")
self.stackedWidget.addWidget(self.righttriangle)
self.Settings = QtWidgets.QWidget()
self.Settings.setObjectName("Settings")
self.label_18 = QtWidgets.QLabel(self.Settings)
self.label_18.setGeometry(QtCore.QRect(50, 270, 101, 16))
font = QtGui.QFont()
font.setPointSize(12)
self.label_18.setFont(font)
self.label_18.setObjectName("label_18")
self.label_19 = QtWidgets.QLabel(self.Settings)
self.label_19.setGeometry(QtCore.QRect(50, 290, 481, 16))
self.label_19.setObjectName("label_19")
self.stackedWidget.addWidget(self.Settings)
self.Square = QtWidgets.QWidget()
self.Square.setObjectName("Square")
self.lineEdit = QtWidgets.QLineEdit(self.Square)
self.lineEdit.setGeometry(QtCore.QRect(40, 330, 81, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.Square)
self.lineEdit_2.setGeometry(QtCore.QRect(150, 330, 81, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton_10 = QtWidgets.QPushButton(self.Square)
self.pushButton_10.setGeometry(QtCore.QRect(50, 370, 61, 23))
self.pushButton_10.setObjectName("pushButton_10")
self.label_4 = QtWidgets.QLabel(self.Square)
self.label_4.setGeometry(QtCore.QRect(40, 310, 251, 16))
self.label_4.setObjectName("label_4")
self.label_8 = QtWidgets.QLabel(self.Square)
self.label_8.setGeometry(QtCore.QRect(40, 280, 131, 16))
font = QtGui.QFont()
font.setFamily("Sitka Heading")
font.setPointSize(12)
self.label_8.setFont(font)
self.label_8.setObjectName("label_8")
self.stackedWidget.addWidget(self.Square)
self.home_2 = QtWidgets.QWidget()
self.home_2.setObjectName("home_2")
self.stackedWidget.addWidget(self.home_2)
self.sqrt = QtWidgets.QWidget()
self.sqrt.setObjectName("sqrt")
self.stackedWidget_2 = QtWidgets.QStackedWidget(self.sqrt)
self.stackedWidget_2.setGeometry(QtCore.QRect(860, 10, 871, 401))
self.stackedWidget_2.setObjectName("stackedWidget_2")
self.home_3 = QtWidgets.QWidget()
self.home_3.setObjectName("home_3")
self.stackedWidget_2.addWidget(self.home_3)
self.one_3 = QtWidgets.QWidget()
self.one_3.setObjectName("one_3")
self.lineEdit_5 = QtWidgets.QLineEdit(self.one_3)
self.lineEdit_5.setGeometry(QtCore.QRect(40, 330, 81, 31))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(self.one_3)
self.lineEdit_6.setGeometry(QtCore.QRect(150, 330, 81, 31))
self.lineEdit_6.setObjectName("lineEdit_6")
self.pushButton_12 = QtWidgets.QPushButton(self.one_3)
self.pushButton_12.setGeometry(QtCore.QRect(50, 370, 61, 23))
self.pushButton_12.setObjectName("pushButton_12")
self.label_6 = QtWidgets.QLabel(self.one_3)
self.label_6.setGeometry(QtCore.QRect(40, 310, 251, 16))
self.label_6.setObjectName("label_6")
self.stackedWidget_2.addWidget(self.one_3)
self.page_3 = QtWidgets.QWidget()
self.page_3.setObjectName("page_3")
self.stackedWidget_2.addWidget(self.page_3)
self.lineEdit_17 = QtWidgets.QLineEdit(self.sqrt)
self.lineEdit_17.setGeometry(QtCore.QRect(110, 330, 81, 31))
self.lineEdit_17.setObjectName("lineEdit_17")
self.lineEdit_18 = QtWidgets.QLineEdit(self.sqrt)
self.lineEdit_18.setGeometry(QtCore.QRect(10, 330, 81, 31))
self.lineEdit_18.setObjectName("lineEdit_18")
self.label_12 = QtWidgets.QLabel(self.sqrt)
self.label_12.setGeometry(QtCore.QRect(10, 310, 281, 16))
self.label_12.setObjectName("label_12")
self.pushButton_18 = QtWidgets.QPushButton(self.sqrt)
self.pushButton_18.setGeometry(QtCore.QRect(20, 370, 61, 23))
self.pushButton_18.setObjectName("pushButton_18")
self.stackedWidget.addWidget(self.sqrt)
self.add = QtWidgets.QWidget()
self.add.setObjectName("add")
self.lineEdit_19 = QtWidgets.QLineEdit(self.add)
self.lineEdit_19.setGeometry(QtCore.QRect(20, 330, 81, 31))
self.lineEdit_19.setObjectName("lineEdit_19")
self.lineEdit_20 = QtWidgets.QLineEdit(self.add)
self.lineEdit_20.setGeometry(QtCore.QRect(120, 330, 81, 31))
self.lineEdit_20.setObjectName("lineEdit_20")
self.pushButton_19 = QtWidgets.QPushButton(self.add)
self.pushButton_19.setGeometry(QtCore.QRect(30, 370, 61, 23))
self.pushButton_19.setObjectName("pushButton_19")
self.pushButton_20 = QtWidgets.QPushButton(self.add)
self.pushButton_20.setGeometry(QtCore.QRect(130, 370, 61, 23))
self.pushButton_20.setObjectName("pushButton_20")
self.lineEdit_21 = QtWidgets.QLineEdit(self.add)
self.lineEdit_21.setGeometry(QtCore.QRect(220, 330, 81, 31))
self.lineEdit_21.setObjectName("lineEdit_21")
self.label_13 = QtWidgets.QLabel(self.add)
self.label_13.setGeometry(QtCore.QRect(20, 310, 261, 16))
self.label_13.setObjectName("label_13")
self.stackedWidget.addWidget(self.add)
self.sidea = QtWidgets.QWidget()
self.sidea.setObjectName("sidea")
self.lineEdit_22 = QtWidgets.QLineEdit(self.sidea)
self.lineEdit_22.setGeometry(QtCore.QRect(20, 320, 81, 31))
self.lineEdit_22.setObjectName("lineEdit_22")
self.lineEdit_23 = QtWidgets.QLineEdit(self.sidea)
self.lineEdit_23.setGeometry(QtCore.QRect(120, 320, 81, 31))
self.lineEdit_23.setObjectName("lineEdit_23")
self.lineEdit_24 = QtWidgets.QLineEdit(self.sidea)
self.lineEdit_24.setGeometry(QtCore.QRect(220, 320, 81, 31))
self.lineEdit_24.setObjectName("lineEdit_24")
self.pushButton_21 = QtWidgets.QPushButton(self.sidea)
self.pushButton_21.setGeometry(QtCore.QRect(130, 350, 61, 23))
self.pushButton_21.setObjectName("pushButton_21")
self.pushButton_22 = QtWidgets.QPushButton(self.sidea)
self.pushButton_22.setGeometry(QtCore.QRect(30, 350, 61, 23))
self.pushButton_22.setObjectName("pushButton_22")
self.label_5 = QtWidgets.QLabel(self.sidea)
self.label_5.setGeometry(QtCore.QRect(10, 300, 101, 16))
self.label_5.setObjectName("label_5")
self.label_7 = QtWidgets.QLabel(self.sidea)
self.label_7.setGeometry(QtCore.QRect(110, 300, 101, 16))
self.label_7.setObjectName("label_7")
self.stackedWidget.addWidget(self.sidea)
self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_8.setGeometry(QtCore.QRect(170, 510, 131, 41))
self.pushButton_8.setObjectName("pushButton_8")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(340, -10, 251, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_20 = QtWidgets.QLabel(self.centralwidget)
self.label_20.setGeometry(QtCore.QRect(330, 520, 221, 16))
self.label_20.setObjectName("label_20")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(8)
self.stackedWidget_2.setCurrentIndex(1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Square a Number"))
self.pushButton_2.setText(_translate("MainWindow", "Find A"))
self.pushButton_3.setText(_translate("MainWindow", "Add numbers"))
self.pushButton_4.setText(_translate("MainWindow", "Square Root a Number"))
self.pushButton_5.setText(_translate("MainWindow", "Find B"))
self.pushButton_6.setText(_translate("MainWindow", "Find C"))
self.label_2.setText(_translate("MainWindow", "Copyright 2020 Zain Raza"))
self.label_3.setText(_translate("MainWindow", "Version 1.1"))
self.pushButton_7.setText(_translate("MainWindow", "Detect Right Triangles"))
self.pushButton_23.setText(_translate("MainWindow", "Enter"))
self.pushButton_24.setText(_translate("MainWindow", "Enter"))
self.label_9.setText(_translate("MainWindow", "Please enter Side A"))
self.label_10.setText(_translate("MainWindow", "Please enter Side C"))
self.pushButton_25.setText(_translate("MainWindow", "Enter"))
self.pushButton_26.setText(_translate("MainWindow", "Enter"))
self.label_11.setText(_translate("MainWindow", "Please enter Side B"))
self.label_14.setText(_translate("MainWindow", "Please enter Side A"))
self.label_15.setText(_translate("MainWindow", "Please enter Side B"))
self.label_16.setText(_translate("MainWindow", "Please enter Side C"))
self.label_17.setText(_translate("MainWindow", "Please enter Side A"))
self.label_18.setText(_translate("MainWindow", "Coming Soon"))
self.label_19.setText(_translate("MainWindow", "For more information please email zain.raza0808#gmail.com or chat on Discord Famous8#6462"))
self.pushButton_10.setText(_translate("MainWindow", "Enter"))
self.label_4.setText(_translate("MainWindow", "Please enter the number you would like to square"))
self.label_8.setText(_translate("MainWindow", "Square a Number"))
self.pushButton_12.setText(_translate("MainWindow", "Enter"))
self.label_6.setText(_translate("MainWindow", "Please enter the number you would like to square"))
self.label_12.setText(_translate("MainWindow", "Please enter the number you would like to Square Root"))
self.pushButton_18.setText(_translate("MainWindow", "Enter"))
self.pushButton_19.setText(_translate("MainWindow", "Enter"))
self.pushButton_20.setText(_translate("MainWindow", "Enter"))
self.label_13.setText(_translate("MainWindow", "Please enter the two numbers you would like to add"))
self.pushButton_21.setText(_translate("MainWindow", "Enter"))
self.pushButton_22.setText(_translate("MainWindow", "Enter"))
self.label_5.setText(_translate("MainWindow", "Please enter Side B"))
self.label_7.setText(_translate("MainWindow", "Please enter Side C"))
self.pushButton_8.setText(_translate("MainWindow", "Settings"))
self.label.setText(_translate("MainWindow", "Pythagoream Theorem Calculator"))
self.label_20.setText(_translate("MainWindow", "Please choose the action you would like to do"))
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_())
In your code:
you are not subclassing your MainWindow. In name == main part. You need MainWindow() not QtWidgets.QMainWindow()
I would also suggest you name your variable differently than your class
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MyWindow = MainWindow()
MyWindow.show()
sys.exit(app.exec_())
Your class should subclass QMainWindow. And your init should starts like this
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = PTCGUI.Ui_MainWindow()
self.ui.setupUi(self)
Remove def show(self). You don't need to call self.ui.show(), you want to call just self.show() directly.
I am making a project on pyqt5. now, its work is to click on one button "Click and Say" which call speech function in which label is updating and we say and it recognize it.
the code is here.
from PyQt5 import QtCore, QtGui, QtWidgets
import urllib
import speech_recognition as sr
import time
def connected(host='http://google.com'):
try:
urllib.request.urlopen(host)
return True
except:
return False
class Ui_Function(object):
def setupUi(self, Function):
Function.setObjectName("Function")
Function.resize(737, 600)
self.centralwidget = QtWidgets.QWidget(Function)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(50, 70, 601, 31))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50, 30, 151, 17))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(320, 120, 67, 17))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(60, 150, 251, 21))
self.label_3.setObjectName("label_3")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(60, 180, 101, 25))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.speech)
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(60, 320, 601, 231))
self.textEdit.setObjectName("textEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(60, 290, 141, 21))
self.label_4.setObjectName("label_4")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(570, 110, 89, 25))
self.pushButton_2.setObjectName("pushButton_2")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(60, 220, 241, 21))
self.label_5.setObjectName("label_5")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(400, 180, 251, 31))
self.comboBox.setObjectName("comboBox")
Function.setCentralWidget(self.centralwidget)
self.retranslateUi(Function)
QtCore.QMetaObject.connectSlotsByName(Function)
def retranslateUi(self, Function):
_translate = QtCore.QCoreApplication.translate
Function.setWindowTitle(_translate("Function", "MainWindow"))
self.label.setText(_translate("Function", "Enter the Book Name:"))
self.label_2.setText(_translate("Function", "OR"))
self.label_3.setText(_translate("Function", "Write the Book Name by your Voice:"))
self.pushButton.setText(_translate("Function", "Click and Say"))
self.label_4.setText(_translate("Function", "Recommendations:"))
self.pushButton_2.setText(_translate("Function", "Clear"))
self.label_5.setText(_translate("Function", "TextLabel"))
def speech(self):
if connected():
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
self.label_5.setText("Listening...")
self.label_5.adjustSize()
time.sleep(1)
# read the audio data from the default microphone
audio_data = r.listen(source,timeout=5)
self.label_5.setText("Time over")
time.sleep(1)
self.label_5.setText("Recognizing...")
time.sleep(1)
# convert speech to text
text = r.recognize_google(audio_data ,language='en-UK', show_all=True)
try:
self.label_5.setText("You said:" )
list1=[]
self.comboBox.clear()
if (len(text)>0):
print(len(text["alternative"]))
for x in range(0,len(text["alternative"])):
list1.append(text["alternative"][x]["transcript"])
self.comboBox.addItems(list1)
else:
time.sleep(1)
self.label_5.setText("\tNothing")
except LookupError:
time.sleep(1)
self.label_5.setText("Could not Understand Value")
except sr.UnknownValueError:
time.sleep(1)
self.label_5.setText("Voice Recognition could not understand audio")
except sr.RequestError as e:
time.sleep(1)
self.label_5.setText("Voice Recognition could not request results ; {0}".format(e))
else:
time.sleep(1)
self.label_5.setText("NO Internet Connection. \nCheck your Internet Connection")
time.sleep(1)
self.label_5.setText("Completed")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Function = QtWidgets.QMainWindow()
ui = Ui_Function()
ui.setupUi(Function)
Function.show()
sys.exit(app.exec_())
This code listens and recognize the word. but the only problem is that all labels are not updating in speech function. Only the last one which contains "completed" is updated.
The flow of program is click on button and then it calls speech function which is listening, recognizing with updation of labels.
I have even add time.sleep(1) before every updation. Any help will be appreciated. I am new to PYqt5.
Tasks that consume a lot of time should not be executed in the GUI thread, instead you must execute it in another thread and send the information through signals.
from PyQt5 import QtCore, QtGui, QtWidgets
import urllib
import speech_recognition as sr
import threading
import time
def connected(host="http://google.com"):
try:
urllib.request.urlopen(host)
return True
except:
return False
class Ui_Function(object):
def setupUi(self, Function):
Function.setObjectName("Function")
Function.resize(737, 600)
self.centralwidget = QtWidgets.QWidget(Function)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(50, 70, 601, 31))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50, 30, 151, 17))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(320, 120, 67, 17))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(60, 150, 251, 21))
self.label_3.setObjectName("label_3")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(60, 180, 101, 25))
self.pushButton.setObjectName("pushButton")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(60, 320, 601, 231))
self.textEdit.setObjectName("textEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(60, 290, 141, 21))
self.label_4.setObjectName("label_4")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(570, 110, 89, 25))
self.pushButton_2.setObjectName("pushButton_2")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(60, 220, 241, 21))
self.label_5.setObjectName("label_5")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(400, 180, 251, 31))
self.comboBox.setObjectName("comboBox")
Function.setCentralWidget(self.centralwidget)
self.retranslateUi(Function)
QtCore.QMetaObject.connectSlotsByName(Function)
def retranslateUi(self, Function):
_translate = QtCore.QCoreApplication.translate
Function.setWindowTitle(_translate("Function", "MainWindow"))
self.label.setText(_translate("Function", "Enter the Book Name:"))
self.label_2.setText(_translate("Function", "OR"))
self.label_3.setText(
_translate("Function", "Write the Book Name by your Voice:")
)
self.pushButton.setText(_translate("Function", "Click and Say"))
self.label_4.setText(_translate("Function", "Recommendations:"))
self.pushButton_2.setText(_translate("Function", "Clear"))
self.label_5.setText(_translate("Function", "TextLabel"))
class SpeechWorker(QtCore.QObject):
messageChanged = QtCore.pyqtSignal(str)
itemsChanged = QtCore.pyqtSignal(list)
def speech(self):
threading.Thread(target=self._speech, daemon=True).start()
def _speech(self):
if connected():
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
self.messageChanged.emit("Listening...")
time.sleep(1)
# read the audio data from the default microphone
audio_data = r.listen(source, timeout=5)
self.messageChanged.emit("Time over")
time.sleep(1)
self.messageChanged.emit("Recognizing...")
time.sleep(1)
# convert speech to text
text = r.recognize_google(audio_data, language="en-UK", show_all=True)
try:
self.messageChanged.emit("You said:")
self.itemsChanged.emit([])
list1 = []
if len(text) > 0:
print(len(text["alternative"]))
for x in range(0, len(text["alternative"])):
list1.append(text["alternative"][x]["transcript"])
self.itemsChanged.emit(list1)
else:
time.sleep(1)
self.messageChanged.emit("\tNothing")
except LookupError:
time.sleep(1)
self.messageChanged.emit("Could not Understand Value")
except sr.UnknownValueError:
time.sleep(1)
self.messageChanged.emit(
"Voice Recognition could not understand audio"
)
except sr.RequestError as e:
time.sleep(1)
self.messageChanged.emit(
"Voice Recognition could not request results ; {0}".format(e)
)
else:
time.sleep(1)
self.messageChanged.emit(
"NO Internet Connection. \nCheck your Internet Connection"
)
time.sleep(1)
self.messageChanged.emit("Completed")
class Function(QtWidgets.QMainWindow, Ui_Function):
def __init__(self, parent=None):
super(Function, self).__init__(parent)
self.setupUi(self)
self.worker = SpeechWorker()
self.worker.messageChanged.connect(self.updateMessage)
self.worker.itemsChanged.connect(self.updateItems)
self.pushButton.clicked.connect(self.worker.speech)
#QtCore.pyqtSlot(str)
def updateMessage(self, message):
self.label_5.setText(message)
self.label_5.adjustSize()
#QtCore.pyqtSlot(list)
def updateItems(self, items):
self.comboBox.clear()
self.comboBox.addItems(items)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Function()
w.show()
sys.exit(app.exec_())
I have trouble time in getting the values from the label and whenever there are number input in the line Edit, it will print once the Total button is click and also I want to have the Reset button wherein it will clear all the data that was made after putting the data.
Expected Outcome
Link: https://drive.google.com/open?id=1RC0RwG23flx5kT7Tbe4FFphM0gTeqRw4
Here is my code that was derived from Qt Designer and added some codes:
from PyQt5 import QtCore, QtGui, QtWidgets
from FinalEditForm import Ui_editWindow
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(634, 578)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_3 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_3.setContentsMargins(10, 10, 10, 10)
self.gridLayout_3.setObjectName("gridLayout_3")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tabWidget.sizePolicy().hasHeightForWidth())
self.tabWidget.setSizePolicy(sizePolicy)
self.tabWidget.setObjectName("tabWidget")
self.widget = QtWidgets.QWidget()
self.widget.setObjectName("widget")
self.gridLayout = QtWidgets.QGridLayout(self.widget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.scrollArea = QtWidgets.QScrollArea(self.widget)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 588, 492))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label.setGeometry(QtCore.QRect(38, 20, 81, 21))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_2.setGeometry(QtCore.QRect(160, 20, 121, 21))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_3.setGeometry(QtCore.QRect(317, 20, 61, 21))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_4.setGeometry(QtCore.QRect(400, 20, 141, 21))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_5.setGeometry(QtCore.QRect(40, 50, 47, 13))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_6.setGeometry(QtCore.QRect(180, 50, 61, 13))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_7.setGeometry(QtCore.QRect(320, 49, 61, 16))
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_8.setGeometry(QtCore.QRect(440, 49, 61, 16))
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_9.setGeometry(QtCore.QRect(40, 70, 47, 13))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_10.setGeometry(QtCore.QRect(180, 70, 58, 13))
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_11.setGeometry(QtCore.QRect(319, 68, 71, 16))
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_12.setGeometry(QtCore.QRect(440, 69, 61, 16))
self.label_12.setObjectName("label_12")
self.label_13 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_13.setGeometry(QtCore.QRect(40, 90, 61, 16))
self.label_13.setObjectName("label_13")
self.label_14 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_14.setGeometry(QtCore.QRect(180, 90, 59, 13))
self.label_14.setObjectName("label_14")
self.label_15 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_15.setGeometry(QtCore.QRect(319, 88, 61, 16))
self.label_15.setObjectName("label_15")
self.label_16 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_16.setGeometry(QtCore.QRect(440, 89, 61, 16))
self.label_16.setObjectName("label_16")
self.label_17 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_17.setGeometry(QtCore.QRect(40, 110, 61, 16))
self.label_17.setObjectName("label_17")
self.label_18 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_18.setGeometry(QtCore.QRect(180, 110, 59, 13))
self.label_18.setObjectName("label_18")
self.label_19 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_19.setGeometry(QtCore.QRect(318, 109, 61, 16))
self.label_19.setObjectName("label_19")
self.label_20 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_20.setGeometry(QtCore.QRect(440, 109, 61, 16))
self.label_20.setObjectName("label_20")
self.pushButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton.setGeometry(QtCore.QRect(490, 440, 75, 23))
self.pushButton.setObjectName("pushButton")
self.label_21 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_21.setGeometry(QtCore.QRect(40, 130, 101, 16))
self.label_21.setObjectName("label_21")
self.label_22 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_22.setGeometry(QtCore.QRect(179, 130, 47, 13))
self.label_22.setObjectName("label_22")
self.label_23 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_23.setGeometry(QtCore.QRect(320, 129, 51, 16))
self.label_23.setObjectName("label_23")
self.label_24 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_24.setGeometry(QtCore.QRect(441, 130, 47, 13))
self.label_24.setObjectName("label_24")
self.label_25 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_25.setGeometry(QtCore.QRect(40, 150, 71, 16))
self.label_25.setObjectName("label_25")
self.label_26 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_26.setGeometry(QtCore.QRect(180, 150, 47, 13))
self.label_26.setObjectName("label_26")
self.label_27 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_27.setGeometry(QtCore.QRect(320, 150, 47, 13))
self.label_27.setObjectName("label_27")
self.label_28 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_28.setGeometry(QtCore.QRect(440, 150, 47, 13))
self.label_28.setObjectName("label_28")
self.label.raise_()
self.label_2.raise_()
self.label_3.raise_()
self.label_4.raise_()
self.label_5.raise_()
self.label_6.raise_()
self.label_7.raise_()
self.label_8.raise_()
self.label_9.raise_()
self.label_10.raise_()
self.label_11.raise_()
self.label_12.raise_()
self.label_13.raise_()
self.label_14.raise_()
self.label_15.raise_()
self.label_16.raise_()
self.label_17.raise_()
self.label_18.raise_()
self.label_19.raise_()
self.label_20.raise_()
self.label_21.raise_()
self.label_22.raise_()
self.label_23.raise_()
self.label_24.raise_()
self.label_25.raise_()
self.label_26.raise_()
self.label_27.raise_()
self.label_28.raise_()
self.pushButton.raise_()
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.gridLayout.addWidget(self.scrollArea, 0, 1, 1, 1)
self.tabWidget.addTab(self.widget, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.checkBox = QtWidgets.QCheckBox(self.tab_2)
self.checkBox.setGeometry(QtCore.QRect(20, 40, 70, 17))
self.checkBox.setObjectName("checkBox")
self.label_29 = QtWidgets.QLabel(self.tab_2)
self.label_29.setGeometry(QtCore.QRect(30, 10, 81, 16))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_29.setFont(font)
self.label_29.setObjectName("label_29")
self.checkBox_2 = QtWidgets.QCheckBox(self.tab_2)
self.checkBox_2.setGeometry(QtCore.QRect(20, 60, 70, 17))
self.checkBox_2.setObjectName("checkBox_2")
self.checkBox_3 = QtWidgets.QCheckBox(self.tab_2)
self.checkBox_3.setGeometry(QtCore.QRect(20, 80, 76, 17))
self.checkBox_3.setObjectName("checkBox_3")
self.checkBox_4 = QtWidgets.QCheckBox(self.tab_2)
self.checkBox_4.setGeometry(QtCore.QRect(20, 100, 78, 17))
self.checkBox_4.setObjectName("checkBox_4")
self.checkBox_5 = QtWidgets.QCheckBox(self.tab_2)
self.checkBox_5.setGeometry(QtCore.QRect(20, 120, 117, 17))
self.checkBox_5.setObjectName("checkBox_5")
self.checkBox_6 = QtWidgets.QCheckBox(self.tab_2)
self.checkBox_6.setGeometry(QtCore.QRect(20, 140, 85, 17))
self.checkBox_6.setObjectName("checkBox_6")
self.label_30 = QtWidgets.QLabel(self.tab_2)
self.label_30.setGeometry(QtCore.QRect(180, 10, 45, 13))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_30.setFont(font)
self.label_30.setObjectName("label_30")
self.label_31 = QtWidgets.QLabel(self.tab_2)
self.label_31.setGeometry(QtCore.QRect(270, 6, 62, 19))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_31.setFont(font)
self.label_31.setObjectName("label_31")
self.label_32 = QtWidgets.QLabel(self.tab_2)
self.label_32.setGeometry(QtCore.QRect(180, 40, 65, 13))
self.label_32.setObjectName("label_32")
self.label_33 = QtWidgets.QLabel(self.tab_2)
self.label_33.setGeometry(QtCore.QRect(180, 60, 63, 13))
self.label_33.setObjectName("label_33")
self.label_34 = QtWidgets.QLabel(self.tab_2)
self.label_34.setGeometry(QtCore.QRect(180, 80, 61, 13))
self.label_34.setObjectName("label_34")
self.label_35 = QtWidgets.QLabel(self.tab_2)
self.label_35.setGeometry(QtCore.QRect(180, 100, 63, 13))
self.label_35.setObjectName("label_35")
self.label_36 = QtWidgets.QLabel(self.tab_2)
self.label_36.setGeometry(QtCore.QRect(180, 120, 47, 13))
self.label_36.setObjectName("label_36")
self.label_37 = QtWidgets.QLabel(self.tab_2)
self.label_37.setGeometry(QtCore.QRect(180, 140, 47, 13))
self.label_37.setObjectName("label_37")
self.lineEdit = QtWidgets.QLineEdit(self.tab_2)
self.lineEdit.setGeometry(QtCore.QRect(260, 35, 91, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.tab_2)
self.lineEdit_2.setGeometry(QtCore.QRect(260, 57, 91, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.tab_2)
self.lineEdit_3.setGeometry(QtCore.QRect(260, 78, 91, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.tab_2)
self.lineEdit_4.setGeometry(QtCore.QRect(260, 99, 91, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.lineEdit_5 = QtWidgets.QLineEdit(self.tab_2)
self.lineEdit_5.setGeometry(QtCore.QRect(260, 120, 91, 20))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(self.tab_2)
self.lineEdit_6.setGeometry(QtCore.QRect(260, 141, 91, 20))
self.lineEdit_6.setObjectName("lineEdit_6")
self.pushButton_2 = QtWidgets.QPushButton(self.tab_2)
self.pushButton_2.setGeometry(QtCore.QRect(350, 470, 70, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.tab_2)
self.pushButton_3.setGeometry(QtCore.QRect(425, 470, 70, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.label_38 = QtWidgets.QLabel(self.tab_2)
self.label_38.setGeometry(QtCore.QRect(520, 471, 16, 16))
self.label_38.setObjectName("label_38")
self.label_39 = QtWidgets.QLabel(self.tab_2)
self.label_39.setGeometry(QtCore.QRect(420, 10, 117, 19))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label_39.setFont(font)
self.label_39.setObjectName("label_39")
self.label_40 = QtWidgets.QLabel(self.tab_2)
self.label_40.setGeometry(QtCore.QRect(450, 38, 66, 13))
self.label_40.setObjectName("label_40")
self.label_41 = QtWidgets.QLabel(self.tab_2)
self.label_41.setGeometry(QtCore.QRect(450, 60, 66, 13))
self.label_41.setObjectName("label_41")
self.label_42 = QtWidgets.QLabel(self.tab_2)
self.label_42.setGeometry(QtCore.QRect(450, 81, 57, 13))
self.label_42.setObjectName("label_42")
self.label_43 = QtWidgets.QLabel(self.tab_2)
self.label_43.setGeometry(QtCore.QRect(450, 102, 55, 13))
self.label_43.setObjectName("label_43")
self.label_44 = QtWidgets.QLabel(self.tab_2)
self.label_44.setGeometry(QtCore.QRect(450, 124, 47, 15))
self.label_44.setObjectName("label_44")
self.label_45 = QtWidgets.QLabel(self.tab_2)
self.label_45.setGeometry(QtCore.QRect(450, 145, 47, 13))
self.label_45.setObjectName("label_45")
self.tabWidget.addTab(self.tab_2, "")
self.gridLayout_3.addWidget(self.tabWidget, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
self.pushButton_2.clicked.connect(self.lineEdit.clear)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Automated System Inventory"))
self.label.setText(_translate("MainWindow", "Item Name"))
self.label_2.setText(_translate("MainWindow", "Number of Stocks"))
self.label_3.setText(_translate("MainWindow", "mSRP"))
self.label_4.setText(_translate("MainWindow", "Sari-Sari Store Price"))
self.label_5.setText(_translate("MainWindow", "RC Small"))
self.label_6.setText(_translate("MainWindow", "120 (bottles)"))
self.label_7.setText(_translate("MainWindow", "8.00/bottle"))
self.label_8.setText(_translate("MainWindow", "10.00/bottle"))
self.label_9.setText(_translate("MainWindow", "RC Big"))
self.label_10.setText(_translate("MainWindow", "48 (bottles)"))
self.label_11.setText(_translate("MainWindow", "21.00/bottle"))
self.label_12.setText(_translate("MainWindow", "24.00/bottle"))
self.label_13.setText(_translate("MainWindow", "Coke (Litro)"))
self.label_14.setText(_translate("MainWindow", "48 (bottles)"))
self.label_15.setText(_translate("MainWindow", "22.00/bottle"))
self.label_16.setText(_translate("MainWindow", "26.00/bottle"))
self.label_17.setText(_translate("MainWindow", "C2 (230 mL)"))
self.label_18.setText(_translate("MainWindow", "48 (bottles)"))
self.label_19.setText(_translate("MainWindow", "10.00/bottle"))
self.label_20.setText(_translate("MainWindow", "12.00/bottle"))
self.pushButton.setText(_translate("MainWindow", "Edit"))
self.label_21.setText(_translate("MainWindow", "555 Tuna(Afritada)"))
self.label_22.setText(_translate("MainWindow", "10 (cans)"))
self.label_23.setText(_translate("MainWindow", "18.00/pc"))
self.label_24.setText(_translate("MainWindow", "22.00/pc"))
self.label_25.setText(_translate("MainWindow", "Cup Noodles"))
self.label_26.setText(_translate("MainWindow", "10 (pcs)"))
self.label_27.setText(_translate("MainWindow", "18.00/pc"))
self.label_28.setText(_translate("MainWindow", "24.00/pc"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.widget), _translate("MainWindow", "Stocks and Price"))
self.checkBox.setText(_translate("MainWindow", "RC Small"))
self.label_29.setText(_translate("MainWindow", "Item Name"))
self.checkBox_2.setText(_translate("MainWindow", "RC Big"))
self.checkBox_3.setText(_translate("MainWindow", "Coke (Litro)"))
self.checkBox_4.setText(_translate("MainWindow", "C2 (230 mL)"))
self.checkBox_5.setText(_translate("MainWindow", "555 Tuna (Afritada)"))
self.checkBox_6.setText(_translate("MainWindow", "Cup Noodles"))
self.label_30.setText(_translate("MainWindow", "Price"))
self.label_31.setText(_translate("MainWindow", "Quantity"))
self.label_32.setText(_translate("MainWindow", "10.00"))
self.label_33.setText(_translate("MainWindow", "24.00"))
self.label_34.setText(_translate("MainWindow", "26.00"))
self.label_35.setText(_translate("MainWindow", "12.00"))
self.label_36.setText(_translate("MainWindow", "22.00"))
self.label_37.setText(_translate("MainWindow", "24.00"))
self.pushButton_2.setText(_translate("MainWindow", "Reset"))
self.pushButton_3.setText(_translate("MainWindow", "Total"))
self.label_38.setText(_translate("MainWindow", "0"))
self.label_39.setText(_translate("MainWindow", "Remaining Stocks"))
self.label_40.setText(_translate("MainWindow", "120 (bottles)"))
self.label_41.setText(_translate("MainWindow", "48(bottles)"))
self.label_42.setText(_translate("MainWindow", "48(bottles)"))
self.label_43.setText(_translate("MainWindow", "48(bottles)"))
self.label_44.setText(_translate("MainWindow", "10 (pc)"))
self.label_45.setText(_translate("MainWindow", "10 (pc)"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Sales"))
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.openWindow)
def openWindow(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_editWindow()
self.ui.setupUi(self.window)
self.window.show()
self.ui.pushButton_2.clicked.connect(self.updateWindow)
def print_click(self):
self.ui.lineEdit.setText(self.label_5.text())
self.ui.lineEdit.setText(self.label_6.text())
self.ui.lineEdit.setText(self.label_7.text())
self.ui.lineEdit.setText(self.label_8.text())
self.ui.lineEdit.setText(self.label_40.text())
self.ui.lineEdit.setText(self.label_32.text())
def updateWindow(self):
self.checkBox.setText(self.ui.lineEdit.text())
self.label_5.setText(self.ui.lineEdit.text())
self.label_40.setText(self.ui.lineEdit_2.text())
self.label_32.setText(self.ui.lineEdit_4.text())
self.label_6.setText(self.ui.lineEdit_2.text())
self.label_7.setText(self.ui.lineEdit_3.text())
self.label_8.setText(self.ui.lineEdit_4.text())
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = MyWindow()
MainWindow.show()
sys.exit(app.exec_())
It might be easier to expand your program if you use a QTableWidget(), especially if you wish to add items dynamically later on.
The example below multiplies(if selected) column 2 with 3 and output the answer next to the pushButton
from PyQt5 import QtCore, QtGui, QtWidgets
class MyWindow(QtWidgets.QMainWindow):
def __init__(self, parent = None):
super(MyWindow, self).__init__(parent)
gLayout = QtWidgets.QGridLayout()
centralWidget = QtWidgets.QWidget(self)
centralWidget.setLayout(gLayout)
self.setCentralWidget(centralWidget)
self.tbl = QtWidgets.QTableWidget()
self.tbl.setRowCount(4)
self.tbl.setColumnCount(3)
btnTotal = QtWidgets.QPushButton("Calculate Selected Rows Col2 * Col3")
self.lblTotal = QtWidgets.QLabel()
gLayout.addWidget(self.tbl, 0, 0, 1, 2)
gLayout.addWidget(btnTotal, 1, 0, 1, 1)
gLayout.addWidget(self.lblTotal, 1, 1, 1, 1)
for i in range(4):
item = QtWidgets.QTableWidgetItem()
item.setCheckState(1)
self.tbl.setItem(i, 0, item)
item = QtWidgets.QTableWidgetItem()
item.setText(str(i + 1))
self.tbl.setItem(i, 1, item)
item = QtWidgets.QTableWidgetItem()
item.setText(str(5))
self.tbl.setItem(i, 2, item)
btnTotal.clicked.connect(self.calc)
def calc(self):
sum = 0
for i in range(4):
if self.tbl.item(i, 0).checkState() == QtCore.Qt.Checked:
#item checked
sum = sum + (int(self.tbl.item(i, 1).text()) * int(self.tbl.item(i, 2).text()))
self.lblTotal.setText(str(sum))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = MyWindow()
MainWindow.show()
sys.exit(app.exec_())
I have 3 files: Gui.py, IPG_weld.py, Reading.py
Gui.py is:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMainWindow
from PyQt5.QtGui import QIcon
from PyQt5 import QtGui
from Ipg_weld import Ui_IPG_weld
class Test(Ui_IPG_weld):
def __init__(self):
super().__init__()
self.widget = QMainWindow()
self.setupUi(self.widget)
...
self.widget.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Test()
sys.exit(app.exec_())
Ipg_Weld.py is:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\IPG_Weld\ipg_weld.ui'
#
# Created by: PyQt5 UI code generator 5.9
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from Reading import reading
class Ui_IPG_weld(object):
def setupUi(self, IPG_weld):
IPG_weld.setObjectName("IPG_weld")
IPG_weld.resize(1107, 641)
self.centralWidget = QtWidgets.QWidget(IPG_weld)
self.centralWidget.setObjectName("centralWidget")
self.Savebutton = QtWidgets.QPushButton(self.centralWidget)
self.Savebutton.setGeometry(QtCore.QRect(930, 520, 131, 51))
self.Savebutton.setObjectName("Savebutton")
self.label = QtWidgets.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(20, 20, 121, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralWidget)
self.label_2.setGeometry(QtCore.QRect(400, 20, 121, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralWidget)
self.label_3.setGeometry(QtCore.QRect(20, 80, 55, 16))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralWidget)
self.label_4.setGeometry(QtCore.QRect(20, 120, 55, 16))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralWidget)
self.label_5.setGeometry(QtCore.QRect(20, 160, 55, 16))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.centralWidget)
self.label_6.setGeometry(QtCore.QRect(400, 90, 55, 16))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.centralWidget)
self.label_7.setGeometry(QtCore.QRect(400, 130, 55, 16))
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.centralWidget)
self.label_8.setGeometry(QtCore.QRect(400, 170, 55, 16))
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(self.centralWidget)
self.label_9.setGeometry(QtCore.QRect(400, 210, 55, 16))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(self.centralWidget)
self.label_10.setGeometry(QtCore.QRect(400, 250, 55, 16))
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(self.centralWidget)
self.label_11.setGeometry(QtCore.QRect(400, 290, 55, 16))
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(self.centralWidget)
self.label_12.setGeometry(QtCore.QRect(400, 330, 55, 16))
self.label_12.setObjectName("label_12")
self.label_13 = QtWidgets.QLabel(self.centralWidget)
self.label_13.setGeometry(QtCore.QRect(400, 370, 55, 16))
self.label_13.setObjectName("label_13")
self.label_14 = QtWidgets.QLabel(self.centralWidget)
self.label_14.setGeometry(QtCore.QRect(400, 410, 55, 16))
self.label_14.setObjectName("label_14")
self.label_15 = QtWidgets.QLabel(self.centralWidget)
self.label_15.setGeometry(QtCore.QRect(400, 450, 55, 16))
self.label_15.setObjectName("label_15")
self.label_16 = QtWidgets.QLabel(self.centralWidget)
self.label_16.setGeometry(QtCore.QRect(400, 490, 55, 16))
self.label_16.setObjectName("label_16")
self.Read_Button = QtWidgets.QPushButton(self.centralWidget)
self.Read_Button.setGeometry(QtCore.QRect(790, 520, 131, 51))
self.Read_Button.setObjectName("Read_Button")
first_text=self.Read_Button.Clicked.Connect(reading())
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit.setGeometry(QtCore.QRect(220, 70, 41, 31))
self.plainTextEdit.setObjectName("plainTextEdit")
self.plainTextEdit_2 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_2.setGeometry(QtCore.QRect(220, 110, 41, 31))
self.plainTextEdit_2.setObjectName("plainTextEdit_2")
self.plainTextEdit_3 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_3.setGeometry(QtCore.QRect(220, 150, 41, 31))
self.plainTextEdit_3.setObjectName("plainTextEdit_3")
self.plainTextEdit_4 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_4.setGeometry(QtCore.QRect(620, 80, 41, 31))
self.plainTextEdit_4.setObjectName("plainTextEdit_4")
self.plainTextEdit_5 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_5.setGeometry(QtCore.QRect(620, 120, 41, 31))
self.plainTextEdit_5.setObjectName("plainTextEdit_5")
self.plainTextEdit_6 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_6.setGeometry(QtCore.QRect(620, 160, 41, 31))
self.plainTextEdit_6.setObjectName("plainTextEdit_6")
self.plainTextEdit_7 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_7.setGeometry(QtCore.QRect(620, 200, 41, 31))
self.plainTextEdit_7.setObjectName("plainTextEdit_7")
self.plainTextEdit_8 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_8.setGeometry(QtCore.QRect(620, 240, 41, 31))
self.plainTextEdit_8.setObjectName("plainTextEdit_8")
self.plainTextEdit_9 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_9.setGeometry(QtCore.QRect(620, 280, 41, 31))
self.plainTextEdit_9.setObjectName("plainTextEdit_9")
self.plainTextEdit_10 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_10.setGeometry(QtCore.QRect(620, 320, 41, 31))
self.plainTextEdit_10.setObjectName("plainTextEdit_10")
self.plainTextEdit_11 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_11.setGeometry(QtCore.QRect(620, 360, 41, 31))
self.plainTextEdit_11.setObjectName("plainTextEdit_11")
self.plainTextEdit_12 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_12.setGeometry(QtCore.QRect(620, 400, 41, 31))
self.plainTextEdit_12.setObjectName("plainTextEdit_12")
self.plainTextEdit_13 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_13.setGeometry(QtCore.QRect(620, 440, 41, 31))
self.plainTextEdit_13.setObjectName("plainTextEdit_13")
self.plainTextEdit_14 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_14.setGeometry(QtCore.QRect(620, 480, 41, 31))
self.plainTextEdit_14.setObjectName("plainTextEdit_14")
self.plainTextEdit_15 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_15.setGeometry(QtCore.QRect(160, 70, 41, 31))
self.plainTextEdit_15.setReadOnly(True)
self.plainTextEdit_15.setObjectName("plainTextEdit_15")
self.plainTextEdit_16 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_16.setGeometry(QtCore.QRect(160, 110, 41, 31))
self.plainTextEdit_16.setReadOnly(True)
self.plainTextEdit_16.setObjectName("plainTextEdit_16")
self.plainTextEdit_17 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_17.setGeometry(QtCore.QRect(160, 150, 41, 31))
self.plainTextEdit_17.setReadOnly(True)
self.plainTextEdit_17.setObjectName("plainTextEdit_17")
self.plainTextEdit_18 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_18.setGeometry(QtCore.QRect(560, 80, 41, 31))
self.plainTextEdit_18.setReadOnly(True)
self.plainTextEdit_18.setObjectName("plainTextEdit_18")
self.plainTextEdit_19 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_19.setGeometry(QtCore.QRect(560, 120, 41, 31))
self.plainTextEdit_19.setReadOnly(True)
self.plainTextEdit_19.setObjectName("plainTextEdit_19")
self.plainTextEdit_20 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_20.setGeometry(QtCore.QRect(560, 160, 41, 31))
self.plainTextEdit_20.setReadOnly(True)
self.plainTextEdit_20.setObjectName("plainTextEdit_20")
self.plainTextEdit_21 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_21.setGeometry(QtCore.QRect(560, 200, 41, 31))
self.plainTextEdit_21.setReadOnly(True)
self.plainTextEdit_21.setObjectName("plainTextEdit_21")
self.plainTextEdit_22 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_22.setGeometry(QtCore.QRect(560, 240, 41, 31))
self.plainTextEdit_22.setReadOnly(True)
self.plainTextEdit_22.setObjectName("plainTextEdit_22")
self.plainTextEdit_23 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_23.setGeometry(QtCore.QRect(560, 280, 41, 31))
self.plainTextEdit_23.setReadOnly(True)
self.plainTextEdit_23.setObjectName("plainTextEdit_23")
self.plainTextEdit_24 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_24.setGeometry(QtCore.QRect(560, 320, 41, 31))
self.plainTextEdit_24.setReadOnly(True)
self.plainTextEdit_24.setObjectName("plainTextEdit_24")
self.plainTextEdit_25 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_25.setGeometry(QtCore.QRect(560, 360, 41, 31))
self.plainTextEdit_25.setReadOnly(True)
self.plainTextEdit_25.setObjectName("plainTextEdit_25")
self.plainTextEdit_26 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_26.setGeometry(QtCore.QRect(560, 400, 41, 31))
self.plainTextEdit_26.setReadOnly(True)
self.plainTextEdit_26.setObjectName("plainTextEdit_26")
self.plainTextEdit_27 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_27.setGeometry(QtCore.QRect(560, 440, 41, 31))
self.plainTextEdit_27.setReadOnly(True)
self.plainTextEdit_27.setObjectName("plainTextEdit_27")
self.plainTextEdit_28 = QtWidgets.QPlainTextEdit(self.centralWidget)
self.plainTextEdit_28.setGeometry(QtCore.QRect(560, 480, 41, 31))
self.plainTextEdit_28.setReadOnly(True)
self.plainTextEdit_28.setObjectName("plainTextEdit_28")
self.label_17 = QtWidgets.QLabel(self.centralWidget)
self.label_17.setGeometry(QtCore.QRect(150, 40, 55, 16))
self.label_17.setObjectName("label_17")
self.label_18 = QtWidgets.QLabel(self.centralWidget)
self.label_18.setGeometry(QtCore.QRect(220, 40, 55, 16))
self.label_18.setObjectName("label_18")
self.label_19 = QtWidgets.QLabel(self.centralWidget)
self.label_19.setGeometry(QtCore.QRect(550, 50, 55, 16))
self.label_19.setObjectName("label_19")
self.label_20 = QtWidgets.QLabel(self.centralWidget)
self.label_20.setGeometry(QtCore.QRect(620, 50, 55, 16))
self.label_20.setObjectName("label_20")
IPG_weld.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(IPG_weld)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 1107, 26))
self.menuBar.setObjectName("menuBar")
IPG_weld.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(IPG_weld)
self.mainToolBar.setObjectName("mainToolBar")
IPG_weld.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtWidgets.QStatusBar(IPG_weld)
self.statusBar.setObjectName("statusBar")
IPG_weld.setStatusBar(self.statusBar)
self.retranslateUi(IPG_weld)
QtCore.QMetaObject.connectSlotsByName(IPG_weld)
def retranslateUi(self, IPG_weld):
_translate = QtCore.QCoreApplication.translate
IPG_weld.setWindowTitle(_translate("IPG_weld", "IPG_weld"))
self.Savebutton.setText(_translate("IPG_weld", "Сохранить"))
self.label.setText(_translate("IPG_weld", "Inputs"))
self.label_2.setText(_translate("IPG_weld", "Outputs"))
self.label_3.setText(_translate("IPG_weld", "Active"))
self.label_4.setText(_translate("IPG_weld", "Ready"))
self.label_5.setText(_translate("IPG_weld", "Error"))
self.label_6.setText(_translate("IPG_weld", "Bit 0"))
self.label_7.setText(_translate("IPG_weld", "Bit 1"))
self.label_8.setText(_translate("IPG_weld", "Bit 2"))
self.label_9.setText(_translate("IPG_weld", "Bit 3"))
self.label_10.setText(_translate("IPG_weld", "Bit 4"))
self.label_11.setText(_translate("IPG_weld", "Bit 5"))
self.label_12.setText(_translate("IPG_weld", "Bit 6"))
self.label_13.setText(_translate("IPG_weld", "Bit 7"))
self.label_14.setText(_translate("IPG_weld", "Bit 8"))
self.label_15.setText(_translate("IPG_weld", "Strobe"))
self.label_16.setText(_translate("IPG_weld", "Start"))
self.Read_Button.setText(_translate("IPG_weld", "Считать значения"))
#self.plainTextEdit_18.setPlainText(_translate("IPG_weld", "1"))
self.plainTextEdit_18.setPlainText(first_edit[1])
self.plainTextEdit_19.setPlainText(_translate("IPG_weld", "2"))
self.plainTextEdit_20.setPlainText(_translate("IPG_weld", "3"))
self.plainTextEdit_21.setPlainText(_translate("IPG_weld", "4"))
self.plainTextEdit_22.setPlainText(_translate("IPG_weld", "5"))
self.plainTextEdit_23.setPlainText(_translate("IPG_weld", "6"))
self.plainTextEdit_24.setPlainText(_translate("IPG_weld", "7"))
self.plainTextEdit_25.setPlainText(_translate("IPG_weld", "8"))
self.plainTextEdit_26.setPlainText(_translate("IPG_weld", "9"))
self.plainTextEdit_27.setPlainText(_translate("IPG_weld", "10"))
self.plainTextEdit_28.setPlainText(_translate("IPG_weld", "11"))
self.label_17.setText(_translate("IPG_weld", "Текущее "))
self.label_18.setText(_translate("IPG_weld", "Новое"))
self.label_19.setText(_translate("IPG_weld", "Текущее "))
self.label_20.setText(_translate("IPG_weld", "Новое"))
And Reading.py is:
import sys
import os
import re
import re
def reading():
with open ('Setup_Weld.src') as f:
stripped=[row.strip() for row in f]
setup_weld_num = [re.search(r'\[(.*?)\]',i).group(1) for i in stripped if re.search(r'\[(.*?)\]',i)]
print(setup_weld_num)
reading()
So what I'm currenlty trying to do is to connect two buttons,that was created in IPG_weld.py (Read_Button and Save_Button) to my events:
When Read_Button clicked , reading() in reading.py should be executed where array Setup_weld_num will be filled, and
PlainTextEdit_18 to PlainTextEdit_28 received elements from setup_weld_num array. In another words, I want to read from file:
&ACCESS RVP1
&REL 3
&PARAM DISKPATH = KRC:\R1\Program\new
DEF SETUP_WELD()
;call LASER_EN();
$out[27]=false; START=OFF
$out[26]=false; STROBE=OFF
$out[25]=false; SELECT 8=OFF
$out[24]=false; SELECT 7 =OFF
$out[23]=false; SELECT 6 =OFF
$out[22]=false; SELECT 5 =OFF
$out[21]=false; SELECT 4 =OFF
$out[20]=false; SELECT 3 =OFF
$out[19]=false; SELECT 2 =OFF
$out[18]=false; SELECT 1 =OFF
$out[17]=false; SELECT 0 =OFF
$out[28]=true; ENABLE=ON
END
And translate number of outputs to Plain_TextEdit_18 - plainTextEdit_25, so the user will able to see them in text box in Gui.
How to do it properly?
UPD: As you can See I added:
first_text=self.Read_Button.Clicked.Connect(reading())
and tried to transfer the 1st element of first_edit array into PlainTextEdit_18:
self.plainTextEdit_18.setPlainText(first_edit[1])
But its not working, because array first_edit is not visible for retranslate_UI function.
As comments on a top of Ipg_weld.py states, it's useless to add any code to this file since it will be rewritten by Qt UI compiler. Consider adding a click handler function to your class Test in Gui.py. For example:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMainWindow
from PyQt5.QtGui import QIcon
from PyQt5 import QtGui
from Ipg_weld import Ui_IPG_weld
import Reading
class Test(Ui_IPG_weld):
def __init__(self):
super().__init__()
self.widget = QMainWindow()
self.setupUi(self.widget)
# ...
self.widget.show()
def read_file(self):
file_values = Reading.reading()
print("Got values:", file_values)
# change this accordingly
self.plainTextEdit.setPlainText(file_values[0])
self.plainTextEdit_2.setPlainText(file_values[1])
# ...
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Test()
sys.exit(app.exec_())
Then you have handler function, connect button signal to it. Note that QPushButton has signal clicked (case matters) and signals has method connect (more about signals and slots in pyqt).
In your example line first_text=self.Read_Button.Clicked.Connect(reading()) actually calls reading (note the parentheses), but while connecting signal and slot you must provide a callable to connect method (consider it like you specifying a name of function rather than calling it).
Summing that up, add connection to your __init__ of class Test:
class Test(Ui_IPG_weld):
def __init__(self):
super().__init__()
self.widget = QMainWindow()
self.setupUi(self.widget)
# ...
# connecting button. Note that you should not call
# self.read_file here.
self.Read_Button.clicked.connect(self.read_file)
self.widget.show()
Now you should see file_values printing while clicking the button.