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())
Related
I have two classes made with pyqt like this:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(409, 119)
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 50, 61, 20))
self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(90, 20, 221, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(90, 50, 221, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(320, 20, 75, 81))
self.pushButton.setObjectName("pushButton")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(20, 20, 61, 20))
self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(20, 80, 61, 20))
self.label_4.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_4.setObjectName("label_4")
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(90, 80, 221, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label_2.setText(_translate("Dialog", "Password"))
self.pushButton.setText(_translate("Dialog", "login"))
self.label_3.setText(_translate("Dialog", "Email"))
self.label_4.setText(_translate("Dialog", "distinct num"))
class Ui_Dialog2(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(485, 429)
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(10, 30, 461, 281))
self.textBrowser.setObjectName("textBrowser")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 10, 121, 16))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 330, 211, 16))
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(10, 350, 391, 20))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(410, 350, 61, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(10, 390, 461, 23))
self.pushButton_2.setObjectName("pushButton_2")
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", "process"))
self.label_2.setText(_translate("Dialog", "file"))
self.pushButton.setText(_translate("Dialog", "select"))
self.pushButton_2.setText(_translate("Dialog", "push"))
These two classes have different window sizes and many different things.
How can I switch between two windows based on the login button of Ui_Dialog?
I know how to trigger on the login button but I don't know how to switch to another class.
I want to move to individual dialogs rather than being done in one dialog.
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 have Ui_MainWindow class, in this class there is a function setupUI and sendmail function.
In setupUI there are lineEdit and lineEdit_2. I have to put text of this variables into the another variables in sendmail def and use it in setupUI How can I do this ?
This code must send text of that line edits to my gmail.
This is code of sendmail func:
class Ui_MainWindow(object):
myaddr = "my#gmail.com"
mypass = "my_password"
toaddr = "your#gmail.com"
def sendmail(label_2, label_3):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(myaddr, mypass)
server.sendmail(myaddr, toaddr, message)
server.quit()
And this is setupUI code:
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(470, 332)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.warface = QtWidgets.QLabel(self.centralwidget)
self.warface.setGeometry(QtCore.QRect(160, 0, 171, 41))
font = QtGui.QFont()
font.setPointSize(22)
self.warface.setFont(font)
self.warface.setObjectName("warface")
self.radioButton = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton.setGeometry(QtCore.QRect(330, 80, 101, 17))
self.radioButton.setObjectName("radioButton")
self.radioButton_2 = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_2.setGeometry(QtCore.QRect(330, 110, 101, 17))
self.radioButton_2.setObjectName("radioButton_2")
self.radioButton_3 = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_3.setGeometry(QtCore.QRect(330, 140, 101, 17))
self.radioButton_3.setObjectName("radioButton_3")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(160, 200, 141, 51))
font = QtGui.QFont()
font.setPointSize(9)
self.pushButton.setFont(font)
self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton.setObjectName("pushButton")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(30, 80, 51, 41))
font = QtGui.QFont()
font.setPointSize(10)
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, 120, 51, 41))
font = QtGui.QFont()
font.setPointSize(10)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(80, 130, 151, 21))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(80, 90, 151, 21))
self.lineEdit_3.setObjectName("lineEdit_3")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 470, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(self.sendmail)
Look at the QLabel.text() function. You can get the text of a label by using
self.label_2.text() and store it in a variable there after myaddr, mypass, toaddr.
Or simply define a variable and give it the self object from setupUI() so you can access its QLabels.
I am trying to update my QLCDNumber, but I failed several times. In my code, you can see that I want to take the input numbers from the double spin boxes and show them as a total sum of the previous land use values in my LCD widget. I have created a function with .value() but it doesn't work properly. The code is bit large, but I highlighted the QLCDNumber part.
Screenshot here:
values to take as inputs
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1039, 654)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 0, 1001, 621))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 241, 521))
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_5.setGeometry(QtCore.QRect(0, 50, 234, 26))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.grass_label = QtWidgets.QLabel(self.layoutWidget_5)
font = QtGui.QFont()
font.setPointSize(12)
self.grass_label.setFont(font)
self.grass_label.setObjectName("grass_label")
self.horizontalLayout_2.addWidget(self.grass_label)
self.grass_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_5)
self.grass_value.setSingleStep(0.05)
self.grass_value.setObjectName("grass_value")
self.horizontalLayout_2.addWidget(self.grass_value)
self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_6.setGeometry(QtCore.QRect(0, 80, 234, 26))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.arable_label = QtWidgets.QLabel(self.layoutWidget_6)
font = QtGui.QFont()
font.setPointSize(12)
self.arable_label.setFont(font)
self.arable_label.setObjectName("arable_label")
self.horizontalLayout_3.addWidget(self.arable_label)
self.arab_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_6)
self.arab_value.setSingleStep(0.05)
self.arab_value.setObjectName("arab_value")
self.horizontalLayout_3.addWidget(self.arab_value)
self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_7.setGeometry(QtCore.QRect(0, 110, 234, 26))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.woodl_label = QtWidgets.QLabel(self.layoutWidget_7)
font = QtGui.QFont()
font.setPointSize(12)
self.woodl_label.setFont(font)
self.woodl_label.setObjectName("woodl_label")
self.horizontalLayout_4.addWidget(self.woodl_label)
self.wood_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_7)
self.wood_value.setSingleStep(0.05)
self.wood_value.setObjectName("wood_value")
self.horizontalLayout_4.addWidget(self.wood_value)
self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_8.setGeometry(QtCore.QRect(0, 140, 234, 26))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.mount_label = QtWidgets.QLabel(self.layoutWidget_8)
font = QtGui.QFont()
font.setPointSize(12)
self.mount_label.setFont(font)
self.mount_label.setObjectName("mount_label")
self.horizontalLayout_5.addWidget(self.mount_label)
self.mount_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_8)
self.mount_value.setSingleStep(0.05)
self.mount_value.setObjectName("mount_value")
self.horizontalLayout_5.addWidget(self.mount_value)
self.start_butt = QtWidgets.QPushButton(self.groupBox)
self.start_butt.setGeometry(QtCore.QRect(50, 290, 113, 32))
self.start_butt.setObjectName("start_butt")
self.landuse_label = QtWidgets.QLabel(self.groupBox)
self.landuse_label.setGeometry(QtCore.QRect(20, 0, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label.setFont(font)
self.landuse_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label.setMidLineWidth(0)
self.landuse_label.setObjectName("landuse_label")
self.increase_label = QtWidgets.QLabel(self.groupBox)
self.increase_label.setGeometry(QtCore.QRect(20, 210, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.increase_label.setFont(font)
self.increase_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.increase_label.setMidLineWidth(0)
self.increase_label.setObjectName("increase_label")
self.rainfall_value = QtWidgets.QDoubleSpinBox(self.groupBox)
self.rainfall_value.setGeometry(QtCore.QRect(50, 240, 110, 24))
self.rainfall_value.setDecimals(1)
self.rainfall_value.setSingleStep(1.0)
self.rainfall_value.setObjectName("rainfall_value")
self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_9.setGeometry(QtCore.QRect(0, 170, 234, 26))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
# Here is the code for the LCD Number
# -----------------------------------------------------------
self.total_label = QtWidgets.QLabel(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(12)
self.total_label.setFont(font)
self.total_label.setObjectName("total_label")
self.horizontalLayout_6.addWidget(self.total_label)
self.total_sum = QtWidgets.QLCDNumber(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(10)
self.total_sum.setFont(font)
self.total_sum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.total_sum.setProperty("value", 0.0)
self.total_sum.setObjectName("total_sum")
self.horizontalLayout_6.addWidget(self.total_sum)
# -----------------------------------------------------------
self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_10.setGeometry(QtCore.QRect(0, 20, 234, 26))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.urban_label = QtWidgets.QLabel(self.layoutWidget_10)
font = QtGui.QFont()
font.setPointSize(12)
self.urban_label.setFont(font)
self.urban_label.setObjectName("urban_label")
self.horizontalLayout_7.addWidget(self.urban_label)
self.urban_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_10)
self.urban_value.setSingleStep(0.05)
self.urban_value.setObjectName("urban_value")
self.horizontalLayout_7.addWidget(self.urban_value)
self.powered_by_label = QtWidgets.QLabel(self.tab)
self.powered_by_label.setGeometry(QtCore.QRect(460, 570, 111, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.powered_by_label.setFont(font)
self.powered_by_label.setObjectName("powered_by_label")
self.landuse_label_2 = QtWidgets.QLabel(self.tab)
self.landuse_label_2.setGeometry(QtCore.QRect(330, 10, 421, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label_2.setFont(font)
self.landuse_label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label_2.setMidLineWidth(0)
self.landuse_label_2.setObjectName("landuse_label_2")
self.hydrograph_widget = QtWidgets.QGroupBox(self.tab)
self.hydrograph_widget.setGeometry(QtCore.QRect(280, 60, 711, 501))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(14)
self.hydrograph_widget.setFont(font)
self.hydrograph_widget.setObjectName("hydrograph_widget")
self.plot_widget = QtWidgets.QWidget(self.hydrograph_widget)
self.plot_widget.setGeometry(QtCore.QRect(10, 30, 691, 461))
self.plot_widget.setObjectName("plot_widget")
self.tabWidget.addTab(self.tab, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1039, 22))
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.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setCheckable(False)
self.actionClose.setObjectName("actionClose")
self.menuMenu.addAction(self.actionClose)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.urban_value, self.grass_value)
MainWindow.setTabOrder(self.grass_value, self.arab_value)
MainWindow.setTabOrder(self.arab_value, self.wood_value)
MainWindow.setTabOrder(self.wood_value, self.mount_value)
MainWindow.setTabOrder(self.mount_value, self.rainfall_value)
MainWindow.setTabOrder(self.rainfall_value, self.start_butt)
MainWindow.setTabOrder(self.start_butt, self.tabWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.grass_label.setText(_translate("MainWindow", "Grassland"))
self.arable_label.setText(_translate("MainWindow", "Arable"))
self.woodl_label.setText(_translate("MainWindow", "Woodland"))
self.mount_label.setText(_translate("MainWindow", "Mountain"))
self.start_butt.setText(_translate("MainWindow", "Start"))
self.landuse_label.setText(_translate("MainWindow", "Land Use Coverage (%)"))
self.increase_label.setText(_translate("MainWindow", "Increase in Rainfall (%)"))
self.total_label.setText(_translate("MainWindow", "Total"))
self.urban_label.setText(_translate("MainWindow", "Urban"))
self.powered_by_label.setText(_translate("MainWindow", "Powered by Group 1"))
self.landuse_label_2.setText(_translate("MainWindow", "Hydrological Modelling for the Ouseburn Catchment"))
self.hydrograph_widget.setTitle(_translate("MainWindow", "Hydrograph"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "HydroModel v.1.0"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionClose.setText(_translate("MainWindow", "Close"))
#---------------------------------------------------------------------
# Here is my code for updating the LCDNumber
def all_inputs(self):
urban_inp = self.urban_value.value()
grass_inp = self.grass_value.value()
arab_inp = self.arab_value.value()
wood_inp = self.wood_value.value()
mount_inp = self.mount_value.value()
total = urban_inp + grass_inp + arab_inp + wood_inp + mount_inp
self.total_sum.display(total)
#---------------------------------------------------------------------
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_())
QDoubleSpinBox::valueChanged(double d)
This signal is emitted whenever the spin box's value is changed.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1039, 654)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 0, 1001, 621))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 241, 521))
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_5.setGeometry(QtCore.QRect(0, 50, 234, 26))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.grass_label = QtWidgets.QLabel(self.layoutWidget_5)
font = QtGui.QFont()
font.setPointSize(12)
self.grass_label.setFont(font)
self.grass_label.setObjectName("grass_label")
self.horizontalLayout_2.addWidget(self.grass_label)
self.grass_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_5)
self.grass_value.setSingleStep(0.05)
self.grass_value.setObjectName("grass_value")
self.horizontalLayout_2.addWidget(self.grass_value)
self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_6.setGeometry(QtCore.QRect(0, 80, 234, 26))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.arable_label = QtWidgets.QLabel(self.layoutWidget_6)
font = QtGui.QFont()
font.setPointSize(12)
self.arable_label.setFont(font)
self.arable_label.setObjectName("arable_label")
self.horizontalLayout_3.addWidget(self.arable_label)
self.arab_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_6)
self.arab_value.setSingleStep(0.05)
self.arab_value.setObjectName("arab_value")
self.horizontalLayout_3.addWidget(self.arab_value)
self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_7.setGeometry(QtCore.QRect(0, 110, 234, 26))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.woodl_label = QtWidgets.QLabel(self.layoutWidget_7)
font = QtGui.QFont()
font.setPointSize(12)
self.woodl_label.setFont(font)
self.woodl_label.setObjectName("woodl_label")
self.horizontalLayout_4.addWidget(self.woodl_label)
self.wood_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_7)
self.wood_value.setSingleStep(0.05)
self.wood_value.setObjectName("wood_value")
self.horizontalLayout_4.addWidget(self.wood_value)
self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_8.setGeometry(QtCore.QRect(0, 140, 234, 26))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.mount_label = QtWidgets.QLabel(self.layoutWidget_8)
font = QtGui.QFont()
font.setPointSize(12)
self.mount_label.setFont(font)
self.mount_label.setObjectName("mount_label")
self.horizontalLayout_5.addWidget(self.mount_label)
self.mount_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_8)
self.mount_value.setSingleStep(0.05)
self.mount_value.setObjectName("mount_value")
self.horizontalLayout_5.addWidget(self.mount_value)
self.start_butt = QtWidgets.QPushButton(self.groupBox)
self.start_butt.setGeometry(QtCore.QRect(50, 290, 113, 32))
self.start_butt.setObjectName("start_butt")
self.landuse_label = QtWidgets.QLabel(self.groupBox)
self.landuse_label.setGeometry(QtCore.QRect(20, 0, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label.setFont(font)
self.landuse_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label.setMidLineWidth(0)
self.landuse_label.setObjectName("landuse_label")
self.increase_label = QtWidgets.QLabel(self.groupBox)
self.increase_label.setGeometry(QtCore.QRect(20, 210, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.increase_label.setFont(font)
self.increase_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.increase_label.setMidLineWidth(0)
self.increase_label.setObjectName("increase_label")
self.rainfall_value = QtWidgets.QDoubleSpinBox(self.groupBox)
self.rainfall_value.setGeometry(QtCore.QRect(50, 240, 110, 24))
self.rainfall_value.setDecimals(1)
self.rainfall_value.setSingleStep(1.0)
self.rainfall_value.setObjectName("rainfall_value")
self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_9.setGeometry(QtCore.QRect(0, 170, 234, 26))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
# Here is the code for the LCD Number
# -----------------------------------------------------------
self.total_label = QtWidgets.QLabel(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(12)
self.total_label.setFont(font)
self.total_label.setObjectName("total_label")
self.horizontalLayout_6.addWidget(self.total_label)
self.total_sum = QtWidgets.QLCDNumber(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(10)
self.total_sum.setFont(font)
self.total_sum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.total_sum.setProperty("value", 0.0)
self.total_sum.setObjectName("total_sum")
self.horizontalLayout_6.addWidget(self.total_sum)
# -----------------------------------------------------------
self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_10.setGeometry(QtCore.QRect(0, 20, 234, 26))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.urban_label = QtWidgets.QLabel(self.layoutWidget_10)
font = QtGui.QFont()
font.setPointSize(12)
self.urban_label.setFont(font)
self.urban_label.setObjectName("urban_label")
self.horizontalLayout_7.addWidget(self.urban_label)
self.urban_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_10)
self.urban_value.setSingleStep(0.05)
self.urban_value.setObjectName("urban_value")
self.horizontalLayout_7.addWidget(self.urban_value)
self.powered_by_label = QtWidgets.QLabel(self.tab)
self.powered_by_label.setGeometry(QtCore.QRect(460, 570, 111, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.powered_by_label.setFont(font)
self.powered_by_label.setObjectName("powered_by_label")
self.landuse_label_2 = QtWidgets.QLabel(self.tab)
self.landuse_label_2.setGeometry(QtCore.QRect(330, 10, 421, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label_2.setFont(font)
self.landuse_label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label_2.setMidLineWidth(0)
self.landuse_label_2.setObjectName("landuse_label_2")
self.hydrograph_widget = QtWidgets.QGroupBox(self.tab)
self.hydrograph_widget.setGeometry(QtCore.QRect(280, 60, 711, 501))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(14)
self.hydrograph_widget.setFont(font)
self.hydrograph_widget.setObjectName("hydrograph_widget")
self.plot_widget = QtWidgets.QWidget(self.hydrograph_widget)
self.plot_widget.setGeometry(QtCore.QRect(10, 30, 691, 461))
self.plot_widget.setObjectName("plot_widget")
self.tabWidget.addTab(self.tab, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1039, 22))
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.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setCheckable(False)
self.actionClose.setObjectName("actionClose")
self.menuMenu.addAction(self.actionClose)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.urban_value, self.grass_value)
MainWindow.setTabOrder(self.grass_value, self.arab_value)
MainWindow.setTabOrder(self.arab_value, self.wood_value)
MainWindow.setTabOrder(self.wood_value, self.mount_value)
MainWindow.setTabOrder(self.mount_value, self.rainfall_value)
MainWindow.setTabOrder(self.rainfall_value, self.start_butt)
MainWindow.setTabOrder(self.start_butt, self.tabWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.grass_label.setText(_translate("MainWindow", "Grassland"))
self.arable_label.setText(_translate("MainWindow", "Arable"))
self.woodl_label.setText(_translate("MainWindow", "Woodland"))
self.mount_label.setText(_translate("MainWindow", "Mountain"))
self.start_butt.setText(_translate("MainWindow", "Start"))
self.landuse_label.setText(_translate("MainWindow", "Land Use Coverage (%)"))
self.increase_label.setText(_translate("MainWindow", "Increase in Rainfall (%)"))
self.total_label.setText(_translate("MainWindow", "Total"))
self.urban_label.setText(_translate("MainWindow", "Urban"))
self.powered_by_label.setText(_translate("MainWindow", "Powered by Group 1"))
self.landuse_label_2.setText(_translate("MainWindow", "Hydrological Modelling for the Ouseburn Catchment"))
self.hydrograph_widget.setTitle(_translate("MainWindow", "Hydrograph"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "HydroModel v.1.0"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionClose.setText(_translate("MainWindow", "Close"))
class Example(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super(Example, self).__init__()
self.setupUi(self)
self.urban_value.valueChanged.connect(self.all_inputs) # +
self.grass_value.valueChanged.connect(self.all_inputs) # +
self.arab_value.valueChanged.connect(self.all_inputs) # +
self.wood_value.valueChanged.connect(self.all_inputs) # +
self.mount_value.valueChanged.connect(self.all_inputs) # +
# Here is my code for updating the LCDNumber
def all_inputs(self):
urban_inp = self.urban_value.value()
grass_inp = self.grass_value.value()
arab_inp = self.arab_value.value()
wood_inp = self.wood_value.value()
mount_inp = self.mount_value.value()
total = urban_inp + grass_inp + arab_inp + wood_inp + mount_inp
self.total_sum.display(total)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Example()
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_())