How to populate Combobox data from SQL? Using Python - python

(Picture 1) - Here is the output of my simple program, supposedly it has 5 dropdown items coming from the database but it only displays 1 data which is the last row of the db that has been read.
Picture 1 -
(Picture 2) - Here is the code, I used for loop and I expect it to loop through it and display every data from db but it only display the last row. Is it wrong syntax or wrong logic?
# Combobox - Subjects
self.cbSubjects = ttk.Combobox(root, width=17, textvariable=self.cbSubjects)
self.cbSubjects.place(x=120, y=60)
# SQL Command
self.conn = cx_Oracle.connect('system/system#127.0.0.1/xe')
self.cursor = self.conn.cursor()
self.cursor.execute("SELECT hr.subject.description FROM hr.subject")
for i in self.cursor:
self.cbSubjects['values'] = (i)
self.cbSubjects.current(0)
self.cursor.close()
self.conn.close()
(Picture 3) - Here is the SQL data that I'd like to display on my Combobox
Picture 3 -
I'm new to Python tkinter. Thank you so much!

Inside the for loop, you are simply overriding the single value you have in your combobox why this line is executed: self.cbSubjects['values'] = (i). The last value you assign to it is the last row returned by the SELECT SQL statement. So this is the explanation of the reason you faced that problem.
For the solution, if you take a look at the documentation which is often your best friend, you can read this:
values Specifies the list of values to display in the drop-down
listbox.
Actually this is a little bit misleading because self.cbSubjects['values'] is rather a tuple, not a list, and as you know tuples are immutable, unlike lists, but still you can overcome this problem by making making i wearing the clothes of a tuple having one single element.
Maybe with code, you will understand the idea better:
#...
for i in self.cursor:
# self.cbSubjects['values'] = (i) , this is bad, change it like this:
self.cbSubjects['values'] = self.cbSubjects['values'] + (i, )
# ... rest of your program

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'delivery.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
conn = sqlite3.connect("spmanager.db")
cursor = conn.cursor()
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(773, 621)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(310, 20, 121, 20))
font = QtGui.QFont()
font.setFamily("Ubuntu Condensed")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.verticalLayoutWidget = QtWidgets.QWidget(Form)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(50, 210, 701, 331))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.tableWidget = QtWidgets.QTableWidget(self.verticalLayoutWidget)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(1)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setVerticalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.verticalLayout.addWidget(self.tableWidget)
self.frame_3 = QtWidgets.QFrame(Form)
self.frame_3.setGeometry(QtCore.QRect(40, 550, 331, 80))
self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.label_4 = QtWidgets.QLabel(self.frame_3)
self.label_4.setGeometry(QtCore.QRect(0, 0, 91, 17))
self.label_4.setObjectName("label_4")
self.textEdit = QtWidgets.QTextEdit(self.frame_3)
self.textEdit.setGeometry(QtCore.QRect(10, 19, 291, 61))
self.textEdit.setObjectName("textEdit")
self.layoutWidget = QtWidgets.QWidget(Form)
self.layoutWidget.setGeometry(QtCore.QRect(50, 70, 691, 91))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.frame_2 = QtWidgets.QFrame(self.layoutWidget)
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.label_3 = QtWidgets.QLabel(self.frame_2)
self.label_3.setGeometry(QtCore.QRect(10, 30, 67, 17))
self.label_3.setObjectName("label_3")
self.dateEdit = QtWidgets.QDateEdit(self.frame_2)
self.dateEdit.setGeometry(QtCore.QRect(70, 20, 151, 41))
self.dateEdit.setObjectName("dateEdit")
self.gridLayout.addWidget(self.frame_2, 0, 1, 1, 1)
self.frame = QtWidgets.QFrame(self.layoutWidget)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.label_2 = QtWidgets.QLabel(self.frame)
self.label_2.setGeometry(QtCore.QRect(20, 30, 71, 21))
self.label_2.setObjectName("label_2")
self.comboBox = QtWidgets.QComboBox(self.frame)
self.comboBox.setGeometry(QtCore.QRect(80, 30, 171, 25))
self.comboBox.setEditable(True)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
#list1 = ['First Item','Second Item','Third Item']
#self.comboBox.addItems(list1)
self.gridLayout.addWidget(self.frame, 0, 0, 1, 1)
self.frame_4 = QtWidgets.QFrame(Form)
self.frame_4.setGeometry(QtCore.QRect(540, 540, 181, 81))
self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_4.setObjectName("frame_4")
self.comboBox_2 = QtWidgets.QComboBox(self.frame_4)
self.comboBox_2.setGeometry(QtCore.QRect(5, 20, 141, 25))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.pushButton = QtWidgets.QPushButton(self.frame_4)
self.pushButton.setGeometry(QtCore.QRect(8, 50, 131, 25))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def customer_names(self):
self.conn = conn
self.cursor = cursor
self.cursor.execute("SELECT customer_name FROM customers ORDER BY customer_name")
self.sql =cursor.fetchall()
customer_names(self)
self.names =[]
for i in self.sql:
self.names.append(i[0])
self.comboBox.addItems(self.names)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "HI-SPECS INNOVATIVE DELIVERY NOTE"))
self.label.setText(_translate("Form", "DELIVERY NOTE"))
item = self.tableWidget.verticalHeaderItem(0)
item.setText(_translate("Form", "1"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("Form", "Qnty"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("Form", "Item"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("Form", "Description"))
self.label_4.setText(_translate("Form", "Comment"))
self.label_3.setText(_translate("Form", "Date:"))
self.label_2.setText(_translate("Form", "Name:"))
self.comboBox.setItemText(0, _translate("Form", "customer"))
self.comboBox_2.setItemText(0, _translate("Form", "Print & Record"))
self.comboBox_2.setItemText(1, _translate("Form", "Print"))
self.comboBox_2.setItemText(2, _translate("Form", "Record"))
self.comboBox_2.setItemText(3, _translate("Form", "Email"))
self.pushButton.setText(_translate("Form", "Continue"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())

Related

name 'QTableWidgetItem' is not defined

I tried install all rquired libsI tried install all rquired libs and Im so sorry I am new here,Im trying to show datas in database on that widget and this problem occurs,I searched all others about that but could not find any issue
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtCore, QtGui, QtWidgets
import mysql.connector
from PyQt5.QtWidgets import QDialog , QApplication , QLineEdit , QInputDialog
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(60, 0, 721, 300))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(7)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(6, item)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(60, 300, 133, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(60, 320, 133, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(60, 340, 133, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(60, 360, 133, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.lineEdit_5 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_5.setGeometry(QtCore.QRect(60, 380, 133, 20))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_6.setGeometry(QtCore.QRect(60, 400, 133, 20))
self.lineEdit_6.setObjectName("lineEdit_6")
self.pushButton = QtWidgets.QPushButton(self.centralwidget,clicked=lambda:self.save())
self.pushButton.setGeometry(QtCore.QRect(193, 300, 91, 121))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(290, 300, 47, 20))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(290, 320, 47, 20))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(290, 340, 47, 20))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(290, 360, 47, 20))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(290, 380, 47, 20))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(290, 400, 47, 20))
self.label_6.setObjectName("label_6")
self.lineEdit_7 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_7.setGeometry(QtCore.QRect(330, 320, 133, 20))
self.lineEdit_7.setObjectName("lineEdit_7")
self.lineEdit_8 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_8.setGeometry(QtCore.QRect(330, 360, 133, 20))
self.lineEdit_8.setObjectName("lineEdit_8")
self.lineEdit_9 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_9.setGeometry(QtCore.QRect(330, 380, 133, 20))
self.lineEdit_9.setObjectName("lineEdit_9")
self.lineEdit_10 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_10.setGeometry(QtCore.QRect(330, 400, 133, 20))
self.lineEdit_10.setObjectName("lineEdit_10")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget,clicked=lambda:self.edit())
self.pushButton_2.setGeometry(QtCore.QRect(460, 300, 91, 121))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "sayı"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "merkez"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "sayac no"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "geliş"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "çıkış"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "fiyat-geliş"))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(_translate("MainWindow", "fiyat-çıkış"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
self.label.setText(_translate("MainWindow", "MERKEZ"))
self.label_2.setText(_translate("MainWindow", "SAYAC"))
self.label_3.setText(_translate("MainWindow", "GELİŞ"))
self.label_4.setText(_translate("MainWindow", "ÇIKIŞ"))
self.label_5.setText(_translate("MainWindow", "GELİŞ-F"))
self.label_6.setText(_translate("MainWindow", "ÇIKIŞ-F"))
self.pushButton_2.setText(_translate("MainWindow", "PushButton"))
def save(self):
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="Tu41893982790",
database="deneme")
mycursor=mydb.cursor()
sql="INSERT INTO sayac(merkez,sayac_no,gelis_tarihi,cikis_tarihi,gelis_fiyati,cikis_fiyati) VALUES(%s,%s,%s,%s,%s,%s)"
val=(str(self.lineEdit.text()),str(self.lineEdit_2.text()),str(self.lineEdit_3.text()),str(self.lineEdit_4.text()),str(self.lineEdit_5.text()),str(self.lineEdit_6.text()))
mycursor.execute(sql,val)
mydb.commit()
def edit(self):
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="Tu41893982790",
database="deneme")
mycursor=mydb.cursor()
sql=f"UPDATE sayac SET cikis_tarihi={self.lineEdit_8.text()},gelis_fiyati={self.lineEdit_9.text()},cikis_fiyati={self.lineEdit_10.text()} WHERE sayac_no={self.lineEdit_7.text()}"
mycursor.execute(sql)
mydb.commit()
def load_data(self):
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="Tu41893982790",
database="deneme")
mycursor=mydb.cursor()
sql="SELECT * FROM sayac"
mycursor.execute(sql)
results=mycursor.fetchall()
results.reverse()
results=list(results)
row=0
for sayac in results:
self.tableWidget.setItem(row,0,QtWidgets,QTableWidgetItem(sayac[0]))
self.tableWidget.setItem(row,1,QtWidgets,QTableWidgetItem(sayac[1]))
self.tableWidget.setItem(row,2,QtWidgets,QTableWidgetItem(sayac[2]))
self.tableWidget.setItem(row,3,QtWidgets,QTableWidgetItem(sayac[3]))
self.tableWidget.setItem(row,4,QtWidgets,QTableWidgetItem(sayac[4]))
self.tableWidget.setItem(row,5,QtWidgets,QTableWidgetItem(sayac[5]))
self.tableWidget.setItem(row,6,QtWidgets,QTableWidgetItem(sayac[6]))
row+=1
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 have noticed that this problem occurs because of 'for sayac in results:' when it is removed,no problem but ı need this loop

pyqt5 button click event works in debug but not when runing

i have a main code that runs a main UI window, from the main UI window im passing to other window, i tried to implement a back button but for some reason it works only when im in debug mode.
main UI window:
from PyQt5 import QtCore, QtGui, QtWidgets
import UI.plantManagment as plantManagment
class Ui_MainWindow(object):
def __init__(self,MainWindow,loadedgreenhouses) -> None:
self.MainWindow=MainWindow
self.loadedgreenhouses=loadedgreenhouses
def setupUi(self):
self.MainWindow.setObjectName("MainWindow")
self.MainWindow.resize(480, 480)
self.MainWindow.setMinimumSize(QtCore.QSize(480, 480))
self.MainWindow.setMaximumSize(QtCore.QSize(480, 480))
self.MainWindow.setTabletTracking(False)
self.MainWindow.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
self.MainWindow.setAnimated(True)
self.MainWindow.setDocumentMode(False)
self.MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(self.MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(70, 70, 321, 361))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.btn_managePlants = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.btn_managePlants.setMinimumSize(QtCore.QSize(0, 80))
font = QtGui.QFont()
font.setPointSize(24)
self.btn_managePlants.setFont(font)
self.btn_managePlants.setObjectName("btn_managePlants")
self.verticalLayout.addWidget(self.btn_managePlants)
self.btn_managePlants.clicked.connect(self.loadPalntsUI)
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem1)
self.btn_manageGreenHouses = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.btn_manageGreenHouses.setMinimumSize(QtCore.QSize(0, 80))
font = QtGui.QFont()
font.setPointSize(24)
self.btn_manageGreenHouses.setFont(font)
self.btn_manageGreenHouses.setObjectName("btn_manageGreenHouses")
self.verticalLayout.addWidget(self.btn_manageGreenHouses)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem2)
self.btn_harvestAll = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.btn_harvestAll.setMinimumSize(QtCore.QSize(0, 80))
font = QtGui.QFont()
font.setPointSize(24)
self.btn_harvestAll.setFont(font)
self.btn_harvestAll.setCheckable(False)
self.btn_harvestAll.setChecked(False)
self.btn_harvestAll.setObjectName("btn_harvestAll")
self.verticalLayout.addWidget(self.btn_harvestAll)
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem3)
self.lable_harvestableNum = QtWidgets.QLabel(self.centralwidget)
self.lable_harvestableNum.setGeometry(QtCore.QRect(70, 20, 321, 41))
font = QtGui.QFont()
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
font.setStrikeOut(False)
font.setKerning(False)
self.lable_harvestableNum.setFont(font)
self.lable_harvestableNum.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lable_harvestableNum.setScaledContents(False)
self.lable_harvestableNum.setAlignment(QtCore.Qt.AlignCenter)
self.lable_harvestableNum.setWordWrap(False)
self.lable_harvestableNum.setIndent(2)
self.lable_harvestableNum.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse)
self.lable_harvestableNum.setObjectName("lable_harvestableNum")
self.MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(self.MainWindow)
self.statusbar.setObjectName("statusbar")
self.MainWindow.setStatusBar(self.statusbar)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self.MainWindow)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.btn_managePlants.setText(_translate("MainWindow", "manage plants"))
self.btn_manageGreenHouses.setText(_translate("MainWindow", "manage greenhouses"))
self.btn_harvestAll.setText(_translate("MainWindow", "harvest all"))
self.lable_harvestableNum.setText(_translate("MainWindow", f"plant ready for harvest: {self.calcRadyToHarvest()}"))
def calcRadyToHarvest(self):
cnt=0
for gh in self.loadedgreenhouses:
for pp in gh.palntingPoints:
if pp.harvestPlant():
cnt+=1
return cnt
def loadPalntsUI(self):
ui = plantManagment.Ui_MainWindow(self.MainWindow,self.loadedgreenhouses)
ui.setupUi()
ui.MainWindow.show()
here the event is working as intended when i click on self.btn_managePlants.clicked.connect(self.loadPalntsUI) and it loads me the next window witouth a problem.
the second window (where the button doesn't work):
from time import sleep
from PyQt5 import QtCore, QtGui, QtWidgets
import Plant
import UI.mainWindow as mainWindow
class Ui_MainWindow(object):
def __init__(self,MainWindow,loadedgreenhouses) -> None:
self.MainWindow=MainWindow
self.loadedgreenhouses=loadedgreenhouses
def setupUi(self):
self.MainWindow.setObjectName("MainWindow")
self.MainWindow.setWindowModality(QtCore.Qt.NonModal)
self.MainWindow.setEnabled(True)
self.MainWindow.resize(627, 409)
self.MainWindow.setMinimumSize(QtCore.QSize(627, 409))
self.MainWindow.setMaximumSize(QtCore.QSize(627, 409))
self.MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(self.MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 20, 591, 361))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label_plants = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(18)
self.label_plants.setFont(font)
self.label_plants.setObjectName("label_plants")
self.verticalLayout.addWidget(self.label_plants)
self.tableWidget = QtWidgets.QTableWidget(self.verticalLayoutWidget)
self.tableWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(4)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.verticalHeader().setVisible(False)
self.tableWidget.verticalHeader().setHighlightSections(False)
self.verticalLayout.addWidget(self.tableWidget)
self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) #forbid editing
self.tableWidget.setRowCount(len(Plant.Plant.kindsList)) #len of number of plants
for i,p in enumerate(Plant.Plant.plantsLst): #add to the table
self.tableWidget.setItem(i, 0, QtWidgets.QTableWidgetItem(p.kind))
self.tableWidget.setItem(i, 1, QtWidgets.QTableWidgetItem(str(p.grow_time)))
self.tableWidget.setItem(i, 2, QtWidgets.QTableWidgetItem(str(p.temp_min)))
self.tableWidget.setItem(i, 3, QtWidgets.QTableWidgetItem(str(p.temp_max)))
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.btn_back = QtWidgets.QPushButton(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(20)
self.btn_back.setFont(font)
self.btn_back.setObjectName("btn_back")
self.horizontalLayout.addWidget(self.btn_back)
self.btn_back.clicked.connect(self.backBtn)
self.btn_delete = QtWidgets.QPushButton(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(20)
self.btn_delete.setFont(font)
self.btn_delete.setObjectName("btn_delete")
self.horizontalLayout.addWidget(self.btn_delete)
self.btn_addPlant = QtWidgets.QPushButton(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(20)
self.btn_addPlant.setFont(font)
self.btn_addPlant.setObjectName("btn_addPlant")
self.horizontalLayout.addWidget(self.btn_addPlant)
self.verticalLayout.addLayout(self.horizontalLayout)
self.MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(self.MainWindow)
self.statusbar.setObjectName("statusbar")
self.MainWindow.setStatusBar(self.statusbar)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self.MainWindow)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.MainWindow.setWindowTitle(_translate("MainWindow", "plant managment"))
self.label_plants.setText(_translate("MainWindow", "plants:"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "kind"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "grow time"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "min temperature"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "max temperature"))
self.btn_back.setText(_translate("MainWindow", "back"))
self.btn_delete.setText(_translate("MainWindow", "delete"))
self.btn_addPlant.setText(_translate("MainWindow", "add plant"))
self.tableWidget.show()
def backBtn(self):
print("the lalala")
ui = mainWindow.Ui_MainWindow(self.MainWindow,self.loadedgreenhouses)
ui.setupUi()
self.MainWindow.show()
the event should be triggered by self.btn_back.clicked.connect(self.backBtn) but as i said it would work only in debug mode.
i tried to self.btn_back.clicked.connect(lambda : self.backBtn()) which did took me back to the main UI window but then none of the buttons in that window worked :|

How to pass parameters bw two windows in pyqt5?

I am working on a password manager gui app. Using Qtdesigner I created a main window where I asked for username and password from user. and a dialog window where display the user their username and passwords for different apps and websites. I also called that dialog window from my main window so that when user press login button then if their login credential is correct , the dialog window will appear.
Now what I want is that when dialog window appears,after clicking push button it should show all data of the user which is stored in a table with that username(like if username is alex then a table with name alex is there in db with username and passwords of different apps/websites).
Hope my question is understandable enough to be answered. I can further clarify if anyone interested to answer.
MY mainwindow file------>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
from main2 import Ui_Dialog
class Ui_MainWindow(object):
def openwindow(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Dialog()
self.ui.setupUi(self.window)
self.window.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(553, 400)
MainWindow.setMinimumSize(QtCore.QSize(553, 400))
MainWindow.setMaximumSize(QtCore.QSize(553, 400))
MainWindow.setAutoFillBackground(False)
MainWindow.setStyleSheet("background-color:\"PowderBlue\"")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(-1, -5, 561, 61))
font = QtGui.QFont()
font.setFamily("Dosis ExtraBold")
font.setPointSize(30)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setStyleSheet("color: rgb(87, 8, 97);")
self.label.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label.setFrameShadow(QtWidgets.QFrame.Plain)
self.label.setLineWidth(7)
self.label.setObjectName("label")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(28, 120, 511, 261))
self.frame.setStyleSheet("background-color: rgb(176, 224, 230);\n"
"")
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.username = QtWidgets.QLineEdit(self.frame)
self.username.setGeometry(QtCore.QRect(224, 0, 261, 41))
font = QtGui.QFont()
font.setFamily("Segoe Print")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
self.username.setFont(font)
self.username.setStyleSheet("border :2px solid purple ;\n"
"background-color:PowderBlue;\n"
"border-radius:5px;\n"
"\n"
"\n"
"\n"
"")
self.username.setText("")
self.username.setEchoMode(QtWidgets.QLineEdit.Normal)
self.username.setPlaceholderText("master user")
self.username.setClearButtonEnabled(False)
self.username.setObjectName("username")
self.label_2 = QtWidgets.QLabel(self.frame)
self.label_2.setGeometry(QtCore.QRect(442, 7, 41, 31))
self.label_2.setStyleSheet("image: url(:/user.png);\n"
"background-color:PowderBlue")
self.label_2.setText("")
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.frame)
self.label_3.setGeometry(QtCore.QRect(450, 69, 31, 31))
self.label_3.setAutoFillBackground(False)
self.label_3.setStyleSheet("image: url(:/key.png);\n"
"background-color:PowderBlue")
self.label_3.setText("")
self.label_3.setObjectName("label_3")
self.password = QtWidgets.QLineEdit(self.frame)
self.password.setGeometry(QtCore.QRect(225, 65, 261, 41))
font = QtGui.QFont()
font.setFamily("Segoe Print")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
self.password.setFont(font)
self.password.setPlaceholderText("master password")
self.password.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
self.password.setStyleSheet("border :2px solid purple ;\n"
"border-radius:5px;")
self.password.setText("")
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.password.setPlaceholderText("")
self.password.setClearButtonEnabled(True)
self.password.setObjectName("password")
self.login_button = QtWidgets.QPushButton(self.frame,clicked=lambda:self.log_in())
self.login_button.setGeometry(QtCore.QRect(280, 130, 41, 31))
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.login_button.setFont(font)
self.login_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.login_button.setAcceptDrops(True)
self.login_button.setAutoFillBackground(False)
self.login_button.setStyleSheet("image: url(:/login.png);")
self.login_button.setText("")
self.login_button.setFlat(True)
self.login_button.setObjectName("login_button")
self.signup_button = QtWidgets.QPushButton(self.frame,clicked=lambda:self.sign_up())
self.signup_button.setGeometry(QtCore.QRect(388, 130, 41, 31))
self.signup_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.signup_button.setMouseTracking(False)
self.signup_button.setAcceptDrops(True)
self.signup_button.setAutoFillBackground(False)
self.signup_button.setStyleSheet("image: url(:/user (2).png);")
self.signup_button.setText("")
self.signup_button.setFlat(True)
self.signup_button.setObjectName("signup_button")
self.label_4 = QtWidgets.QLabel(self.frame)
self.label_4.setGeometry(QtCore.QRect(25, 7, 141, 141))
self.label_4.setStyleSheet("image: url(:/team.png);")
self.label_4.setText("")
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.frame)
self.label_5.setGeometry(QtCore.QRect(17, 135, 171, 41))
font = QtGui.QFont()
font.setFamily("Forte")
font.setPointSize(22)
font.setBold(False)
font.setWeight(50)
self.label_5.setFont(font)
self.label_5.setStyleSheet("color: rgb(5, 22, 127);")
self.label_5.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label_5.setFrameShadow(QtWidgets.QFrame.Plain)
self.label_5.setLineWidth(7)
self.label_5.setObjectName("label_5")
self.error_lbl = QtWidgets.QLabel(self.frame)
self.error_lbl.setGeometry(QtCore.QRect(230,165,251,50))
#self.error_lbl.textFormat.RichText()
font = QtGui.QFont()
font.setFamily("Roboto Black")
font.setPointSize(11)
font.setBold(True)
font.setWeight(65)
self.error_lbl.setFont(font)
self.error_lbl.setStyleSheet("color: rgb(255,0,0);")
self.error_lbl.setFrameShape(QtWidgets.QFrame.NoFrame)
self.error_lbl.setFrameShadow(QtWidgets.QFrame.Plain)
self.error_lbl.setLineWidth(1)
self.error_lbl.setObjectName("error_lbl")
self.line_2 = QtWidgets.QFrame(self.frame)
self.line_2.setGeometry(QtCore.QRect(-17, 190, 20, 61))
self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.line_5 = QtWidgets.QFrame(self.frame)
self.line_5.setGeometry(QtCore.QRect(520, -20, 20, 221))
self.line_5.setFrameShape(QtWidgets.QFrame.VLine)
self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_5.setObjectName("line_5")
self.label_6 = QtWidgets.QLabel(self.frame)
self.label_6.setGeometry(QtCore.QRect(349, 231, 41, 31))
self.label_6.setStyleSheet("image: url(:/copyright.png);")
self.label_6.setText("")
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.frame)
self.label_7.setGeometry(QtCore.QRect(380, 234, 111, 20))
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_7.setFont(font)
self.label_7.setObjectName("label_7")
self.password.raise_()
self.username.raise_()
self.label_2.raise_()
self.label_3.raise_()
self.login_button.raise_()
self.signup_button.raise_()
self.label_4.raise_()
self.label_5.raise_()
self.error_lbl.raise_()
self.line_2.raise_()
self.line_5.raise_()
self.label_6.raise_()
self.label_7.raise_()
self.info_button = QtWidgets.QPushButton(self.centralwidget)
self.info_button.setGeometry(QtCore.QRect(510, 0, 41, 23))
self.info_button.setStyleSheet("image: url(:/information-button.png);")
self.info_button.setText("")
self.info_button.setFlat(True)
self.info_button.setObjectName("info_button")
self.line_3 = QtWidgets.QFrame(self.centralwidget)
self.line_3.setGeometry(QtCore.QRect(9, 101, 20, 271))
self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_3.setObjectName("line_3")
self.line_6 = QtWidgets.QFrame(self.centralwidget)
self.line_6.setGeometry(QtCore.QRect(520, 101, 21, 271))
self.line_6.setFrameShape(QtWidgets.QFrame.VLine)
self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_6.setObjectName("line_6")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(334, 0, 81, 61))
self.label_8.setStyleSheet("image: url(:/password.png);")
self.label_8.setText("")
self.label_8.setObjectName("label_8")
self.line_8 = QtWidgets.QFrame(self.centralwidget)
self.line_8.setGeometry(QtCore.QRect(19, 90, 511, 20))
self.line_8.setFrameShape(QtWidgets.QFrame.HLine)
self.line_8.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_8.setObjectName("line_8")
self.line_4 = QtWidgets.QFrame(self.centralwidget)
self.line_4.setGeometry(QtCore.QRect(19, 364, 361, 16))
self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_4.setObjectName("line_4")
self.line_7 = QtWidgets.QFrame(self.centralwidget)
self.line_7.setGeometry(QtCore.QRect(513, 364, 16, 16))
self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_7.setObjectName("line_7")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 553, 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)
def log_in(self):
conn = sqlite3.connect("master.db")
cur = conn.cursor()
user = self.username.text()
password = self.password.text()
print(user)
print(password)
if user=="" or password=="" :
self.error_lbl.setText( "materuser & masterpassword\nrequired !")
else:
cur.execute("SELECT rowid , *FROM master_database WHERE master_users = ?", (user,))
c=cur.fetchone()
conn.commit()
conn.close()
if c==None:
self.error_lbl.setText( f"No data for {user}\nKindly register for new user !" )
else:
if c[2] == password:
#self.error_lbl.setText("Successfully verified.\nClick to Login")
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Dialog()
self.ui.setupUi(self.window)
self.window.show()
else:
self.error_lbl.setText("Incorrect Password !" )
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_())
My Dialog window file------->'
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main2.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
class Ui_Dialog(object):
def loaddata(self):
connection = sqlite3.connect('master.db')
query = "SELECT * FROM a"
c = connection.execute(query)
self.tableWidget.setRowCount(0)
for row_number , row_data in enumerate(c):
self.tableWidget.insertRow(row_number)
for column_number ,data in enumerate(row_data):
self.tableWidget.setItem(row_number,column_number,QtWidgets.QTableWidgetItem(str(data)))
connection.commit()
connection.close()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(553, 424)
font = QtGui.QFont()
font.setFamily("Consolas")
Dialog.setFont(font)
Dialog.setStyleSheet("background-color: PowderBlue;bn ")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(36, 112, 151, 31))
font = QtGui.QFont()
font.setFamily("Raleway Black")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setGeometry(QtCore.QRect(225, 112, 111, 31))
font = QtGui.QFont()
font.setFamily("Raleway Black")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(Dialog)
self.label_6.setGeometry(QtCore.QRect(396, 112, 121, 31))
font = QtGui.QFont()
font.setFamily("Raleway Black")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.tableWidget = QtWidgets.QTableWidget(Dialog)
self.tableWidget.setGeometry(QtCore.QRect(10, 150, 531, 271))
self.tableWidget.setMinimumSize(QtCore.QSize(531, 271))
self.tableWidget.setMaximumSize(QtCore.QSize(531, 271))
font = QtGui.QFont()
font.setFamily("Source Sans Pro SemiBold")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.tableWidget.setFont(font)
self.tableWidget.setStyleSheet("color: rgb(73, 6, 127);")
self.tableWidget.setFrameShape(QtWidgets.QFrame.Box)
self.tableWidget.setGridStyle(QtCore.Qt.NoPen)
self.tableWidget.setRowCount(10)
self.tableWidget.setColumnCount(3)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.horizontalHeader().setDefaultSectionSize(177)
self.pushButton = QtWidgets.QPushButton(Dialog,clicked=lambda:self.loaddata())
self.pushButton.setGeometry(QtCore.QRect(200, 30, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label_4.setText(_translate("Dialog", "APP/WEBSITE"))
self.label_5.setText(_translate("Dialog", "USERNAME"))
self.label_6.setText(_translate("Dialog", "PASSWORD"))
self.pushButton.setText(_translate("Dialog", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
I use the QStackedWidget to switch between pages.
app = QApplication(sys.argv)
stackedwidget = QtWidgets.QStackedWidget()
page1 = PageOneClass()
page2 = PageTwoClass()
stackedwidget.addWidget(page1)
stackedwidget.addWidget(page2)
stackedwidget.show()
app.exec_()
This will let you switch between pages without running another file. Now to get values from one page to another, use inheritance.
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.user = self.username.text()
self password = self.password.text() #Now the user, password can be accessed using the class name. dont forget to add self.
class DialogWindow(MainWindow):
def __init__(self, MainWindow):
super(DialogWindow, self).__init__()
usernamefrompage1 = MainWindow.user
passwordfrompage1 = MainWindow.password
app = QApplication(sys.argv)
stackedwidget = QtWidgets.QStackedWidget()
mainwindow_instance = MainWindow()
dialogwindow_instance = DialogWindow(mainwindow_instance)
#we are passing the mainwindow instance to the dialog window instance, this will let us use all the methods and attributes of the mainwindow.
stackedwidget.addWidget(mainwindow_instance)
stackedwidget.addWidget(dialogwindow_instance)
stackedwidget.setCurrentWidget(mainwindow_instance)
stackedwidget.show()
app.exec_()

i am trying to fetch the data from mysql in pyqt5 and display it in a table widget

here is the whole code. The problem I am having is i cannot get the data from lineTextEdit box to the %s wild card character in the mysql query. it works fine if i hard code the query and give a value from the database but the python stops and closes itself when i try to give the %s in query.
from PyQt5 import QtCore, QtGui, QtWidgets
import mysql.connector
mydb = mysql.connector.connect(
host = "localhost",
username = "sameer",
password = "Pr#tik123",
database = "myschool")
class Ui_Search(object):
def Submit_btn(self):
firstname = self.fname.text()
frstname = firstname.replace(" ", "")
mycursor = mydb.cursor()
for example in first line of code below if i write fname = 'germany' it works totally fine and i get the result in the tablewidget as i intended to but it fails if i give the following %s wild card character .
query = ("select * from students where fname = %s")
mycursor.execute(query,(frstname))
data = mycursor.fetchall()
#self.table.setRowCount(0)
for row_num, rowdata in enumerate(data):
#self.table.insertRow(row_num)
for col_num, coldata in enumerate(rowdata):
self.table.setItem(row_num,col_num,QtWidgets.QTableWidgetItem(str(coldata)))
mycursor.close()
def setupUi(self, Search):
Search.setObjectName("Search")
Search.resize(828, 620)
self.centralwidget = QtWidgets.QWidget(Search)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 10, 91, 31))
font = QtGui.QFont()
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(50, 70, 71, 31))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(340, 70, 71, 31))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(590, 70, 71, 31))
self.label_4.setObjectName("label_4")
self.fname = QtWidgets.QLineEdit(self.centralwidget)
self.fname.setGeometry(QtCore.QRect(20, 100, 151, 22))
self.fname.setObjectName("fname")
self.lname = QtWidgets.QLineEdit(self.centralwidget)
self.lname.setGeometry(QtCore.QRect(300, 100, 151, 22))
self.lname.setObjectName("lname")
self.dob = QtWidgets.QLineEdit(self.centralwidget)
self.dob.setGeometry(QtCore.QRect(570, 100, 161, 22))
self.dob.setObjectName("dob")
self.Submit = QtWidgets.QPushButton(self.centralwidget)
self.Submit.setGeometry(QtCore.QRect(20, 140, 93, 28))
self.Submit.setObjectName("Submit")
self.Submit.clicked.connect(self.Submit_btn)
self.table = QtWidgets.QTableWidget(self.centralwidget)
self.table.setGeometry(QtCore.QRect(20, 180, 791, 421))
self.table.setRowCount(4)
self.table.setColumnCount(6)
self.table.setObjectName("table")
item = QtWidgets.QTableWidgetItem()
self.table.setItem(0, 0, item)
item = QtWidgets.QTableWidgetItem()
self.table.setItem(0, 1, item)
item = QtWidgets.QTableWidgetItem()
self.table.setItem(0, 2, item)
item = QtWidgets.QTableWidgetItem()
self.table.setItem(0, 3, item)
item = QtWidgets.QTableWidgetItem()
self.table.setItem(0, 4, item)
item = QtWidgets.QTableWidgetItem()
self.table.setItem(0, 5, item)
Search.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(Search)
self.statusbar.setObjectName("statusbar")
Search.setStatusBar(self.statusbar)
self.retranslateUi(Search)
QtCore.QMetaObject.connectSlotsByName(Search)
def retranslateUi(self, Search):
_translate = QtCore.QCoreApplication.translate
Search.setWindowTitle(_translate("Search", "MainWindow"))
self.label.setText(_translate("Search", "Search"))
self.label_2.setText(_translate("Search", "First Name"))
self.label_3.setText(_translate("Search", "Last Name"))
self.label_4.setText(_translate("Search", "Date of Birth"))
self.Submit.setText(_translate("Search", "Submit"))
__sortingEnabled = self.table.isSortingEnabled()
self.table.setSortingEnabled(False)
self.table.setSortingEnabled(__sortingEnabled)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Search = QtWidgets.QMainWindow()
ui = Ui_Search()
ui.setupUi(Search)
Search.show()
sys.exit(app.exec_())
Sorry, if this is stupid and the whole bulk of code but i am desperately wanting to solve this problem. It displays no error msg but the python closes itself

Is there a way to change a label of one window from another window?

I've got some code that checks which checkboxes a user clicks. Those are then put into an array (aylm). Once the user clicks the book button, a small confirmation window pops up which says are you sure you want to book these rooms. In this confirmation window, I would like the label to say are you sure you want to book (aylm)? so that all the rooms and times selected can be seen by the user. I am not sure how to go about this since I'm using one main window which connects all the smaller windows together, which you can see below in the code.
class Ui_DialogBook(QtWidgets.QDialog, Ui_DialogBook):
def __init__(self, parent=None):
super(Ui_DialogBook, self).__init__(parent)
self.setupUi(self)
class Ui_ViewAllRooms(QtWidgets.QMainWindow, Ui_ViewAllRooms):
def __init__(self, parent=None):
super(Ui_ViewAllRooms, self).__init__(parent)
self.setupUi(self)
self.dialogBook = Ui_DialogBook()
self.book_Button.clicked.connect(self.dialogBook.show)
self.book_Button.clicked.connect(self.book_clicked)
#QtCore.pyqtSlot()
def book_clicked(self):
items = []
for i in range(self.tableWidget.rowCount()):
for j in range(self.tableWidget.columnCount()):
item = self.tableWidget.item(i, j)
if item.checkState() == QtCore.Qt.Checked:
items.append(item)
for it in items:
r = it.row()
c = it.column()
v, h = self.tableWidget.horizontalHeaderItem(c).text(), self.tableWidget.verticalHeaderItem(r).text()
self._checked_items.append([h, v])
aylm = (self.checked_items())
aylm_len = len(aylm)
for nm in range (0, aylm_len):
print (aylm[nm])
def checked_items(self):
return self._checked_items
The auto generated code from PyQt designer for the Ui_DialogBook is below:
class Ui_DialogBook(object):
def setupUi(self, DialogBook):
DialogBook.setObjectName("DialogBook")
DialogBook.setMaximumSize(QtCore.QSize(200, 150))
self.invalidLogin_label = QtWidgets.QLabel(DialogBook)
self.invalidLogin_label.setGeometry(QtCore.QRect(10, 10, 181, 71))
self.invalidLogin_label.setAlignment(QtCore.Qt.AlignCenter)
self.invalidLogin_label.setObjectName("invalidLogin_label")
self.no_button = QtWidgets.QPushButton(DialogBook)
self.no_button.setGeometry(QtCore.QRect(110, 100, 75, 23))
self.no_button.setObjectName("no_button")
self.yes_button = QtWidgets.QPushButton(DialogBook)
self.yes_button.setGeometry(QtCore.QRect(20, 100, 75, 23))
self.yes_button.setObjectName("yes_button")
self.retranslateUi(DialogBook)
QtCore.QMetaObject.connectSlotsByName(DialogBook)
def retranslateUi(self, DialogBook):
_translate = QtCore.QCoreApplication.translate
DialogBook.setWindowTitle(_translate("DialogBook", "Dialog"))
self.invalidLogin_label.setText(_translate("DialogBook", "Are you sure you would like \n to book:\n"))
self.no_button.setText(_translate("DialogBook", "No"))
self.yes_button.setText(_translate("DialogBook", "Yes"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
DialogBook = QtWidgets.QDialog()
ui = Ui_DialogBook()
ui.setupUi(DialogBook)
DialogBook.show()
sys.exit(app.exec_())
Ui_ViewAllRooms
from PyQt5.QtCore import QDate, QTime, QDateTime, Qt
class Ui_ViewAllRooms(object):
def setupUi(self, ViewAllRooms):
ViewAllRooms.setObjectName("ViewAllRooms")
ViewAllRooms.resize(671, 347)
ViewAllRooms.setMinimumSize(QtCore.QSize(671, 347))
ViewAllRooms.setMaximumSize(QtCore.QSize(671, 347))
self.centralwidget = QtWidgets.QWidget(ViewAllRooms)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(10, 100, 651, 181))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(6)
self.tableWidget.setRowCount(5)
self.tableWidget.setHorizontalHeaderLabels("P1 P2 P3 P4 P5 P6".split())
self.tableWidget.setVerticalHeaderLabels("C101 C214 C320 F04 E201".split())
for i in range(self.tableWidget.rowCount()):
for j in range(self.tableWidget.columnCount()):
item = QtWidgets.QTableWidgetItem()
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Unchecked)
self.tableWidget.setItem(i, j, item)
self._checked_items = []
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 290, 231, 41))
self.label.setObjectName("label")
self.book_Button = QtWidgets.QPushButton(self.centralwidget)
self.book_Button.setGeometry(QtCore.QRect(300, 290, 75, 23))
self.book_Button.setObjectName("book_Button")
self.backButton = QtWidgets.QPushButton(self.centralwidget)
self.backButton.setGeometry(QtCore.QRect(590, 10, 75, 23))
self.backButton.setObjectName("backButton")
self.login_title = QtWidgets.QLabel(self.centralwidget)
self.login_title.setGeometry(QtCore.QRect(220, 10, 231, 38))
font = QtGui.QFont()
font.setFamily("Gloucester MT Extra Condensed")
font.setPointSize(25)
font.setBold(False)
font.setItalic(False)
font.setUnderline(True)
font.setWeight(50)
self.login_title.setFont(font)
self.login_title.setLayoutDirection(QtCore.Qt.LeftToRight)
self.login_title.setAutoFillBackground(False)
self.login_title.setAlignment(QtCore.Qt.AlignCenter)
self.login_title.setObjectName("login_title")
self.date_label = QtWidgets.QLabel(self.centralwidget)
self.date_label.setGeometry(QtCore.QRect(240, 70, 191, 21))
self.date_label.setAlignment(QtCore.Qt.AlignCenter)
self.date_label.setObjectName("date_label")
self.nextDayButton = QtWidgets.QPushButton(self.centralwidget)
self.nextDayButton.setGeometry(QtCore.QRect(590, 70, 75, 23))
self.nextDayButton.setObjectName("nextDayButton")
ViewAllRooms.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(ViewAllRooms)
self.statusbar.setObjectName("statusbar")
ViewAllRooms.setStatusBar(self.statusbar)
self.retranslateUi(ViewAllRooms)
QtCore.QMetaObject.connectSlotsByName(ViewAllRooms)
def retranslateUi(self, ViewAllRooms):
_translate = QtCore.QCoreApplication.translate
ViewAllRooms.setWindowTitle(_translate("ViewAllRooms", "MainWindow"))
item = self.tableWidget.verticalHeaderItem(0)
item.setText(_translate("ViewAllRooms", "C101"))
item.setToolTip("Hall")
item = self.tableWidget.verticalHeaderItem(1)
item.setText(_translate("ViewAllRooms", "C214"))
item.setToolTip("Study Space")
item = self.tableWidget.verticalHeaderItem(2)
item.setText(_translate("ViewAllRooms", "C320"))
item.setToolTip("Computer")
item = self.tableWidget.verticalHeaderItem(3)
item.setText(_translate("ViewAllRooms", "F04"))
item.setToolTip("Mac Room")
item = self.tableWidget.verticalHeaderItem(4)
item.setText(_translate("ViewAllRooms", "E201"))
item.setToolTip("Computer")
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("ViewAllRooms", "P1"))
item.setToolTip("8:55")
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("ViewAllRooms", "P2"))
item.setToolTip("9:55")
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("ViewAllRooms", "P3"))
item.setToolTip("11:15")
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("ViewAllRooms", "P4"))
item.setToolTip("12:15")
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("ViewAllRooms", "P5"))
item.setToolTip("2:00")
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("ViewAllRooms", "P6"))
item.setToolTip("3:15")
__sortingEnabled = self.tableWidget.isSortingEnabled()
self.tableWidget.setSortingEnabled(False)
self.tableWidget.setSortingEnabled(__sortingEnabled)
self.book_Button.setText(_translate("ViewAllRooms", "Book"))
self.backButton.setText(_translate("ViewAllRooms", "Back"))
self.login_title.setText(_translate("ViewAllRooms", "VIEW ALL ROOMS"))
self.date_label.setText(_translate("ViewAllRooms", "Date:14 January 2019"))
self.label.setText(_translate("ViewAllRooms", "Hover over a room number or period for\n"
"extra information"))
self.nextDayButton.setText(_translate("ViewAllRooms", "Next Day"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ViewAllRooms = QtWidgets.QMainWindow()
ui = Ui_ViewAllRooms()
ui.setupUi(ViewAllRooms)
ViewAllRooms.show()
sys.exit(app.exec_())
View All Rooms GUI
Try it :
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class Ui_DialogBook(object):
def setupUi(self, DialogBook):
DialogBook.setObjectName("DialogBook")
DialogBook.setMaximumSize(QtCore.QSize(200, 150))
self.invalidLogin_label = QtWidgets.QLabel(DialogBook)
self.invalidLogin_label.setGeometry(QtCore.QRect(10, 10, 181, 71))
self.invalidLogin_label.setAlignment(QtCore.Qt.AlignCenter)
self.invalidLogin_label.setObjectName("invalidLogin_label")
self.no_button = QtWidgets.QPushButton(DialogBook)
self.no_button.setGeometry(QtCore.QRect(110, 100, 75, 23))
self.no_button.setObjectName("no_button")
self.yes_button = QtWidgets.QPushButton(DialogBook)
self.yes_button.setGeometry(QtCore.QRect(20, 100, 75, 23))
self.yes_button.setObjectName("yes_button")
self.retranslateUi(DialogBook)
QtCore.QMetaObject.connectSlotsByName(DialogBook)
def retranslateUi(self, DialogBook):
_translate = QtCore.QCoreApplication.translate
DialogBook.setWindowTitle(_translate("DialogBook", "Dialog"))
self.invalidLogin_label.setText(_translate("DialogBook", "Are you sure you would like \n to book:\n"))
self.no_button.setText(_translate("DialogBook", "No"))
self.yes_button.setText(_translate("DialogBook", "Yes"))
class DialogBook(QtWidgets.QDialog, Ui_DialogBook):
def __init__(self, parent=None):
super(DialogBook, self).__init__(parent)
self.setupUi(self)
self.listWidget = QListWidget()
self.grid = QGridLayout(self)
self.grid.addWidget(self.invalidLogin_label, 0, 0, 1, 2)
self.grid.addWidget(self.listWidget, 1, 0, 1, 2)
self.grid.addWidget(self.yes_button, 2, 0)
self.grid.addWidget(self.no_button, 2, 1)
class Ui_ViewAllRooms(object):
def setupUi(self, ViewAllRooms):
ViewAllRooms.setObjectName("ViewAllRooms")
ViewAllRooms.resize(671, 347)
ViewAllRooms.setMinimumSize(QtCore.QSize(671, 347))
ViewAllRooms.setMaximumSize(QtCore.QSize(671, 347))
self.centralwidget = QtWidgets.QWidget(ViewAllRooms)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(10, 100, 651, 181))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(6)
self.tableWidget.setRowCount(5)
self.tableWidget.setHorizontalHeaderLabels("P1 P2 P3 P4 P5 P6".split())
self.tableWidget.setVerticalHeaderLabels("C101 C214 C320 F04 E201".split())
for i in range(self.tableWidget.rowCount()):
for j in range(self.tableWidget.columnCount()):
item = QtWidgets.QTableWidgetItem()
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Unchecked)
self.tableWidget.setItem(i, j, item)
self._checked_items = []
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 290, 231, 41))
self.label.setObjectName("label")
self.book_Button = QtWidgets.QPushButton(self.centralwidget)
self.book_Button.setGeometry(QtCore.QRect(300, 290, 75, 23))
self.book_Button.setObjectName("book_Button")
self.backButton = QtWidgets.QPushButton(self.centralwidget)
self.backButton.setGeometry(QtCore.QRect(590, 10, 75, 23))
self.backButton.setObjectName("backButton")
self.login_title = QtWidgets.QLabel(self.centralwidget)
self.login_title.setGeometry(QtCore.QRect(220, 10, 231, 38))
font = QtGui.QFont()
font.setFamily("Gloucester MT Extra Condensed")
font.setPointSize(25)
font.setBold(False)
font.setItalic(False)
font.setUnderline(True)
font.setWeight(50)
self.login_title.setFont(font)
self.login_title.setLayoutDirection(QtCore.Qt.LeftToRight)
self.login_title.setAutoFillBackground(False)
self.login_title.setAlignment(QtCore.Qt.AlignCenter)
self.login_title.setObjectName("login_title")
self.date_label = QtWidgets.QLabel(self.centralwidget)
self.date_label.setGeometry(QtCore.QRect(240, 70, 191, 21))
self.date_label.setAlignment(QtCore.Qt.AlignCenter)
self.date_label.setObjectName("date_label")
self.nextDayButton = QtWidgets.QPushButton(self.centralwidget)
self.nextDayButton.setGeometry(QtCore.QRect(590, 70, 75, 23))
self.nextDayButton.setObjectName("nextDayButton")
ViewAllRooms.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(ViewAllRooms)
self.statusbar.setObjectName("statusbar")
ViewAllRooms.setStatusBar(self.statusbar)
self.retranslateUi(ViewAllRooms)
QtCore.QMetaObject.connectSlotsByName(ViewAllRooms)
def retranslateUi(self, ViewAllRooms):
_translate = QtCore.QCoreApplication.translate
ViewAllRooms.setWindowTitle(_translate("ViewAllRooms", "MainWindow"))
item = self.tableWidget.verticalHeaderItem(0)
item.setText(_translate("ViewAllRooms", "C101"))
item.setToolTip("Hall")
item = self.tableWidget.verticalHeaderItem(1)
item.setText(_translate("ViewAllRooms", "C214"))
item.setToolTip("Study Space")
item = self.tableWidget.verticalHeaderItem(2)
item.setText(_translate("ViewAllRooms", "C320"))
item.setToolTip("Computer")
item = self.tableWidget.verticalHeaderItem(3)
item.setText(_translate("ViewAllRooms", "F04"))
item.setToolTip("Mac Room")
item = self.tableWidget.verticalHeaderItem(4)
item.setText(_translate("ViewAllRooms", "E201"))
item.setToolTip("Computer")
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("ViewAllRooms", "P1"))
item.setToolTip("8:55")
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("ViewAllRooms", "P2"))
item.setToolTip("9:55")
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("ViewAllRooms", "P3"))
item.setToolTip("11:15")
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("ViewAllRooms", "P4"))
item.setToolTip("12:15")
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("ViewAllRooms", "P5"))
item.setToolTip("2:00")
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("ViewAllRooms", "P6"))
item.setToolTip("3:15")
__sortingEnabled = self.tableWidget.isSortingEnabled()
self.tableWidget.setSortingEnabled(False)
self.tableWidget.setSortingEnabled(__sortingEnabled)
self.book_Button.setText(_translate("ViewAllRooms", "Book"))
self.backButton.setText(_translate("ViewAllRooms", "Back"))
self.login_title.setText(_translate("ViewAllRooms", "VIEW ALL ROOMS"))
self.date_label.setText(_translate("ViewAllRooms", "Date:14 January 2019"))
self.label.setText(_translate("ViewAllRooms", "Hover over a room number or period for\n"
"extra information"))
self.nextDayButton.setText(_translate("ViewAllRooms", "Next Day"))
class ViewAllRooms(QtWidgets.QMainWindow, Ui_ViewAllRooms):
def __init__(self, parent=None):
super(ViewAllRooms, self).__init__(parent)
self.setupUi(self)
self.dialogBook = DialogBook() #Ui_DialogBook() #
# self.book_Button.clicked.connect(self.dialogBook.show)
self.book_Button.clicked.connect(self.book_clicked)
#QtCore.pyqtSlot()
def book_clicked(self):
self._checked_items = []
# items = []
for i in range(self.tableWidget.rowCount()):
for j in range(self.tableWidget.columnCount()):
item = self.tableWidget.item(i, j)
if item.checkState() == QtCore.Qt.Checked:
# items.append(item)
# r = it.row()
# c = it.column()
v = self.tableWidget.horizontalHeaderItem(j).text()
h = self.tableWidget.verticalHeaderItem(i).text()
self._checked_items.append([h, v, self.tableWidget.item(i, j).text()])
self.dialogBook.listWidget.clear()
self.dialogBook.listWidget.addItems([ "{} {} {}".format(h, v, it) for h, v, it in self._checked_items])
self.dialogBook.show()
"""
print("items->", items)
for it in items:
r = it.row()
c = it.column()
v, h = self.tableWidget.horizontalHeaderItem(c).text(), self.tableWidget.verticalHeaderItem(r).text()
print("item---", self.tableWidget.item(r, c).text())
self._checked_items.append([h, v])
aylm = (self.checked_items())
aylm_len = len(aylm)
for nm in range (0, aylm_len):
print (aylm[nm])
def checked_items(self):
return self._checked_items
"""
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
DialogBook = ViewAllRooms()
# DialogBook = QtWidgets.QDialog()
# ui = DialogBook()
# ui.setupUi(DialogBook)
DialogBook.show()
sys.exit(app.exec_())

Categories

Resources