Python Forum

Full Version: TypeError
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am learning Python, QT Designer and SQLite using a kindle book (Learn SQLite with Python
Building database-driven desktop projects), written by Vivian Siahaan and Rismon Hasiholan Sianipar. I have not found a way to contact the authors by text or email.

I am 25% through the book with no issues. I am trying to determine the index number of a combo box. Line 208 in teacher_functionalities.py, "index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString)" generates this error message "TypeError: 'PySide2.QtWidgets.QComboBox.findText' called with wrong argument types:"

Python 3.9.5
Idle, Visual Studeo Code 1.58.0
QT Designer 5.15.2
SQLite 3.35.5

Terminal Error Msg

Windows PowerShell
Copyright © Microsoft Corporation. All rights reserved.

PS C:\Files\Python39\scripts> & 'C:\Users\Jim\AppData\Local\Programs\Python\Python39\python.exe' 'c:\Users\Jim\.vscode\extensions\ms-python.python-2021.6.944021595\pythonFiles\lib\python\debugpy\launcher' '51703' '--' 'c:\Files\Python39\scripts\teacher_functionalities.py'
Traceback (most recent call last):
File "c:\Files\Python39\scripts\teacher_functionalities.py", line 721, in <module>
w = TeacherForm()
File "c:\Files\Python39\scripts\teacher_functionalities.py", line 42, in __init__
self.show_first_row_class()
File "c:\Files\Python39\scripts\teacher_functionalities.py", line 208, in show_first_row_class
index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString)
TypeError: 'PySide2.QtWidgets.QComboBox.findText' called with wrong argument types:
PySide2.QtWidgets.QComboBox.findText(str, MatchFlag)
Supported signatures:
PySide2.QtWidgets.QComboBox.findText(str, PySide2.QtCore.Qt.MatchFlags = Instance(Qt.MatchFlags(Qt.MatchExactly | Qt.MatchCaseSensitive)))
PS C:\Files\Python39\scripts>


# teacher_functionalities.py July 9 - 2021

import sqlite3
from sqlite3 import Error
from PyQt5.QtWidgets import QDialog, QApplication, QTableWidgetItem, QFileDialog
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPixmap
from gui_school import *
from datetime import datetime

db_file = r"C:\sqlite3\School.db"

NoRow=1

class TeacherForm(QDialog):

    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.pbShowTeacher.clicked.connect(self.show_teacher_data)
        self.ui.pbFirst.clicked.connect(self.show_first_row)
        self.ui.pbLast.clicked.connect(self.show_last_row)
        self.ui.pbPrevious.clicked.connect(self.show_previous_row)
        self.ui.pbNext.clicked.connect(self.show_next_row)
        

        self.show()
        self.show_first_row()
        self.show_teacher_data()
        self.ui.pbEditTeacher.clicked.connect(self.edit_teacher)
        self.ui.pbChoosePhotoTeacher.clicked.connect(self.display_photo)
        self.ui.pbInsertTeacher.clicked.connect(self.insert_teacher)
        self.ui.pbDeleteTeacher.clicked.connect(self.delete_teacher)
        self.show_combobox_teacher_name()

        self.ui.cbTeacherNameClass.currentIndexChanged.connect(self.show_teacher_id_from_combo_teacher_name)
       

        self.show_data_class_on_tabel()   
        # self.ui.pbShowClass.clicked.connect(self.show_data_class_on_tabel)
        self.show_first_row_class()
        self.ui.pbFirstClass.clicked.connect(self.show_first_row_class)

        """
        self.ui.pbShowClass.clicked.connect(self.show_data_class_on_tabel)
        self.ui.pbLastClass.clicked.connect(self.show_last_row_class)
        self.ui.pbPreviousClass.clicked.connect(self.show_previous_row_class)           
        self.ui.pbNextClass.clicked.connect(self.show_next_row_class)
        self.ui.pbEditClass.clicked.connect(self.edit_class)
        self.ui.pbInsertClass.clicked.connect(self.insert_class)
        self.ui.pbDeleteClass.clicked.connect(self.delete_class)   


        # ************************* Class **************************
    
    def show_previous_row_class(self):
        global NoRowClass
        NoRowClass -= 1

        sqlSELECT = "SELECT TClass.tclass_id, TClass.teacher_id, \
                        TClass.tclass_name, TClass.tclass_code, \
                        Teacher.complete_name FROM TClass \
                        INNER JOIN Teacher ON TClass.teacher_id = Teacher.teacher_id \
                        WHERE tclass_id="+str(NoRowClass)
        try:
            conn = sqlite3.connect(db_file)
                            
            if conn is not None:
                cur = conn.cursor()
                cur.execute(sqlSELECT)
                row = cur.fetchone()

                if row is not None:
                    self.ui.leIDClass.setText(str(row[0]))
                    self.ui.leIDTeacherClass.setText(str(row[1]))
                    self.ui.leNameClass.setText(row[2])
                    self.ui.leCodeClass.setText(row[3])

                    # Determine index of combo box
                    index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString)

                    if index >= 0:
                        self.ui.cbTeacherNameClass.setCurrentIndex(index)
                                                    
                    # Disable all widgets when display mode
                    self.disableWidgetClass(True)

                else:
                    NoRowClass += 1
                    print("This is the first row")

        except Error as e:
            print("Fail to acces table")
        finally:
            conn.close()

    def show_next_row_class(self):
        global NoRowClass
        NoRowClass += 1

        sqlSELECT = "SELECT TClass.tclass_id, TClass.teacher_id, \
                    TClass.tclass_name, TClass.tclass_code, \
                    Teacher.complete_name FROM TClass \
                    INNER JOIN Teacher ON TClass.teacher_id = Teacher.teacher_id \
                    WHERE tclass_id="+str(NoRowClass)

        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(sqlSELECT)
                row = cur.fetchone()

                if row is not None:
                    self.ui.leIDClass.setText(str(row[0]))
                    self.ui.leIDTeacherClass.setText(str(row[1]))
                    self.ui.leNameClass.setText(row[2])
                    self.ui.leCodeClass.setText(row[3])

                    # Determine index of combo box
                    index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString)
                    if index >= 0:
                        self.ui.cbTeacherNameClass.setCurrentIndex(index)

                    # Disable all widgets when display mode
                    self.disableWidgetClass(True)
					
                else:
                    NoRowClass -= 1
                    print("This is the last row")

        except Error as e:
            print("Fail to acces table")

        finally:
            conn.close()





    def show_last_row_class(self):
        global NoRowClass
        sqlSELECT = "SELECT TClass.tclass_id, TClass.teacher_id, \
                        TClass.tclass_name, TClass.tclass_code, \
                        Teacher.complete_name FROM TClass \
                        INNER JOIN Teacher ON TClass.teacher_id = Teacher.teacher_id \
                        ORDER BY tclass_id DESC LIMIT 1"
        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(sqlSELECT)
                row = cur.fetchone()

                if row is not None:
                    self.ui.leIDClass.setText(str(row[0]))
                    self.ui.leIDTeacherClass.setText(str(row[1]))
                    self.ui.leNameClass.setText(row[2])
                    self.ui.leCodeClass.setText(row[3])

                    # Determine index of combo box
                    index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString)
                    
                    if index >= 0:
                        self.ui.cbTeacherNameClass.setCurrentIndex(index)

                    # Disable all widgets when display mode
                    self.disableWidgetClass(True)

                    NoRowClass = row[0]
                else:
                    print("This is the last row")
        
        except Error as e:
            print("Fail to acces table")
        finally:
            conn.close()  """

    
    def show_first_row_class(self):
        global NoRowClass
        sqlSELECT = "SELECT TClass.tclass_id, TClass.teacher_id, \
                            TClass.tclass_name, TClass.tclass_code, \
                            Teacher.complete_name FROM TClass \
                            INNER JOIN Teacher ON TClass.teacher_id = Teacher.teacher_id"

        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(sqlSELECT)
                row = cur.fetchone()

                if row is not None:

                    self.ui.leIDClass.setText(str(row[0]))
                    self.ui.leIDTeacherClass.setText(str(row[1]))
                    self.ui.leNameClass.setText(row[2])
                    self.ui.leCodeClass.setText(row[3])
                    
                    # Determine index of combo box
                    
                    index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString) # *********** Line 208 error **********


                    if index >= 0:
                        self.ui.cbTeacherNameClass.setCurrentIndex(index)

                    # Disable all widgets when display mode
                    self.disableWidgetClass(True)

                    NoRowClass = row[0]
                else:
                    print("This is the first row")
            
        except Error as e:
            print("Fail to acces table")
        finally:
            conn.close()
            
    
    def disableWidgetClass(self, readOnly):
        self.ui.leIDClass.setReadOnly(readOnly)
        self.ui.leNameClass.setReadOnly(readOnly)
        self.ui.leCodeClass.setReadOnly(readOnly)
        self.ui.cbTeacherNameClass.setEnabled(not readOnly)
    

    def show_data_class_on_tabel(self):
        # Clear Table Widget
        self.ui.twClass.clear()

        # To show table headers
        column = ['Class ID', 'Teacher ID', 'Class Name', 'Class Code']
        self.ui.twClass.setHorizontalHeaderLabels(column)

        statemenSQL="SELECT * FROM TClass"

        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(statemenSQL)
                row = cur.fetchall()

                NoRow=0

                for tuple in row:
                    noCol=0

                    for col in tuple:
                        oneCol=QTableWidgetItem(str(col))
                        self.ui.twClass.setItem(NoRow, noCol, oneCol)

                        noCol+=1

                    NoRow+=1

        except Error as e:
            self.ui.twClass.clear()
            print(e)
        finally:
            conn.close() 


    def show_teacher_id_from_combo_teacher_name(self):

        indexComboBox = self.ui.cbTeacherNameClass.currentText()

        sqlSELECT = "SELECT teacher_id FROM Teacher WHERE complete_name = ?"

        data = (indexComboBox,)

        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(sqlSELECT, data)
                record = cur.fetchone()
                self.ui.leIDTeacherClass.setText(str(record[0]))

        except Error as e:

            print("An error occurred while displaying rows of data")

        finally:

            conn.close()  


    def show_combobox_teacher_name(self):

        statemenSQL = "SELECT complete_name FROM Teacher"

        try:  
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(statemenSQL)

                # To fill cbTeacherNameClass combo box

                result = cur.fetchall()

                for record in result:
                    teacher_name = "%s" %record
                    self.ui.cbTeacherNameClass.addItem(teacher_name)
                    # self.ui.cbTeacherNameSubject.addItem(teacher_name)
                    # self.ui.cbTeacherNameQuery.addItem(teacher_name)

        except Error as e:
            print(e) 
        finally:
            conn.close()


# ************************* Teacher **************************

    def delete_teacher(self):
        try:  
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()  
                statemenSQL = "DELETE FROM Teacher WHERE teacher_id = "+self.ui.leTeacherID.text()
                cur.execute(statemenSQL)
                conn.commit()
                print(cur.rowcount, " record has been deleted")
        except Error as e:
            print(e)
        finally:
            conn.close()


    def internal_insert_teacher(self):
        statemenSQL="INSERT INTO Teacher(complete_name, birth_date,\
            gender, blood_type, address, telephone, email,\
            password, photo)\
            VALUES('"+self.ui.leTeacherName.text()+"',\
                    '"+str(self.ui.deTeacherBirth.text())+"', \
                    '"+self.ui.leTeacherGender.text()+"', \
                    '"+self.ui.leTeacherBlood.text()+"', \
                    '"+self.ui.leTeacherAddress.text()+"', \
                    '"+self.ui.leTeacherTelephone.text()+"', \
                    '"+self.ui.leTeacherEmail.text()+"', \
                    '"+self.ui.leTeacherPassword.text()+"', \
                    '"+self.ui.labelPathPhoto.text()+"')"  
        try:
            conn = sqlite3.connect(db_file)
            if conn is not None:
                cur = conn.cursor()
                cur.execute(statemenSQL)
                conn.commit()
                print("Data row inserted successfully")
                self.clearWidgets()

        except Error as e:
            print(e)
        finally:
            conn.close()


    def insert_teacher(self):
        if self.ui.pbInsertTeacher.text() == "INSERT TEACHER" :
            self.ui.pbShowTeacher.setEnabled(False)
            self.ui.pbEditTeacher.setEnabled(False)
            self.ui.pbInsertTeacher.setText("CONFIRM")

            # Enable all widgets for editing
            self.disableWidgets(False)

            # Keep disabling id teacher
            self.ui.leTeacherID.setReadOnly(True)

            # Disabling navigation buttons
            self.ui.pbFirst.setEnabled(False)
            self.ui.pbPrevious.setEnabled(False)
            self.ui.pbNext.setEnabled(False)
            self.ui.pbLast.setEnabled(False)
            # Clear widgets
            self.clearWidgets()

        else :
            self.ui.pbInsertTeacher.setText("INSERT TEACHER")
            self.ui.pbShowTeacher.setEnabled(True)
            self.ui.pbEditTeacher.setEnabled(True)
            self.ui.pbInsertTeacher.setEnabled(True)

            # Disable all widgets for editing
            self.disableWidgets(True)

            # Enabling the navigation buttons
            self.ui.pbFirst.setEnabled(True)
            self.ui.pbPrevious.setEnabled(True)
            self.ui.pbNext.setEnabled(True)
            self.ui.pbLast.setEnabled(True)

            # Inserting data row
            self.internal_insert_teacher()

            print("Data successfully inserted")
            
    def clearWidgets(self):
        self.ui.leTeacherID.clear()
        self.ui.leTeacherName.clear()
        self.ui.deTeacherBirth.setEnabled(True)
        self.ui.leTeacherGender.clear()
        self.ui.leTeacherBlood.clear()
        self.ui.leTeacherAddress.clear()
        self.ui.leTeacherTelephone.clear()
        self.ui.leTeacherEmail.clear()
        self.ui.leTeacherPassword.clear()
        self.ui.pbChoosePhotoTeacher.setEnabled(True)
        pixmap = QPixmap('null.jpg')
        self.ui.labelPathPhoto.setPixmap(pixmap)

    def display_photo(self):
        global photofilename
        filename = QFileDialog.getOpenFileName(self, 'OpenFile')
        pixmap = QPixmap(filename[0])
        self.ui.labelPathPhoto.setPixmap(pixmap)
        self.ui.labelPathPhoto.setText(filename[0])

    def edit_teacher(self):
        if self.ui.pbEditTeacher.text() == "EDIT TEACHER" :
            self.ui.pbShowTeacher.setEnabled(False)
            self.ui.pbInsertTeacher.setEnabled(False)
            self.ui.pbEditTeacher.setText("CONFIRM")

            # Enable all widgets for editing
            self.disableWidgets(False)

            # Keep disabling teacher id
            self.ui.leTeacherID.setReadOnly(True)

            # Disabling navigation buttons
            self.ui.pbFirst.setEnabled(False)
            self.ui.pbPrevious.setEnabled(False)
            self.ui.pbNext.setEnabled(False)
            self.ui.pbLast.setEnabled(False)
        else :

            self.ui.pbEditTeacher.setText("EDIT TEACHER")
            self.ui.pbShowTeacher.setEnabled(True)
            self.ui.pbEditTeacher.setEnabled(True)
            self.ui.pbInsertTeacher.setEnabled(True)

            # Disable all widgets
            self.disableWidgets(True)

            # Reactivating the navigation buttons
            self.ui.pbFirst.setEnabled(True)
            self.ui.pbPrevious.setEnabled(True)
            self.ui.pbNext.setEnabled(True)
            self.ui.pbLast.setEnabled(True)

            # Editing
            self.internal_edit_teacher()

            print("Data edited successfully")

    def internal_edit_teacher(self):
        global photofilename

        # prepare queries and data
        query = """UPDATE Teacher SET complete_name = ?, \
                birth_date = ?, gender = ?, blood_type = ?,\
                address = ?, telephone = ?, email = ?, password = ?, \
                photo = ? WHERE teacher_id = ?"""

        teacher_id = self.ui.leTeacherID.text()
        complete_name = self.ui.leTeacherName.text()
        birth_date = self.ui.deTeacherBirth.text()
        gender = self.ui.leTeacherGender.text()
        blood_type = self.ui.leTeacherBlood.text()
        address = self.ui.leTeacherAddress.text()
        telephone = self.ui.leTeacherTelephone.text()
        email = self.ui.leTeacherEmail.text()
        password = self.ui.leTeacherPassword.text()
        photo = self.ui.labelPathPhoto.text()

        data = (complete_name, birth_date, gender,  blood_type, address, telephone, email, password, photo, teacher_id)

        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(query, data)
                conn.commit()
                print("Data updated successfully")

        except Error as e:
            print(e)
            print("An error occurred while editing data")
        finally:
            conn.close()


    def disableWidgets(self, readOnly):
        self.ui.leTeacherID.setReadOnly(readOnly)
        self.ui.leTeacherName.setReadOnly(readOnly)
        self.ui.deTeacherBirth.setReadOnly(readOnly)
        self.ui.leTeacherGender.setReadOnly(readOnly)
        self.ui.leTeacherBlood.setReadOnly(readOnly)
        self.ui.leTeacherAddress.setReadOnly(readOnly)
        self.ui.leTeacherTelephone.setReadOnly(readOnly)
        self.ui.leTeacherEmail.setReadOnly(readOnly)
        self.ui.leTeacherPassword.setReadOnly(readOnly)


    def show_first_row(self):
        global NoRow
        NoRow = 1
        statemenSQL="SELECT * FROM Teacher ORDER BY teacher_id ASC;"
        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(statemenSQL)
                row = cur.fetchone()
                self.ui.leTeacherID.setText(str(row[0]))
                self.ui.leTeacherName.setText(row[1])
                self.ui.deTeacherBirth.setDate(datetime.strptime(row[2], '%m/%d/%Y').date())
                self.ui.leTeacherGender.setText(row[3])
                self.ui.leTeacherBlood.setText(row[4])
                self.ui.leTeacherAddress.setText(row[5])
                self.ui.leTeacherTelephone.setText(row[6])
                self.ui.leTeacherEmail.setText(row[7])
                self.ui.leTeacherPassword.setText(row[8])

                # Display photo
                if row[9] is None:
                    pixmap = QPixmap('null.jpg')
                    self.ui.labelPathPhoto.setPixmap(pixmap) 
                else:
                    pixmap = QPixmap(row[9])
                    self.ui.labelPathPhoto.setPixmap(pixmap)

                # Disables all line edit widgets

                self. disableWidgets(True)
                NoRow = row[0]

        except Error as e:
            print("Failed to access table")
        finally:
            conn.close()

    def show_previous_row(self):
        global NoRow
        NoRow -= 1

        statemenSQL="SELECT * FROM Teacher WHERE teacher_id="+str(NoRow)
        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor() 
                cur.execute(statemenSQL)
                row = cur.fetchone()
                self.ui.leTeacherID.setText(str(row[0]))
                self.ui.leTeacherName.setText(row[1])
                self.ui.deTeacherBirth.setDate(datetime.strptime(row[2], '%m/%d/%Y').date())
                self.ui.leTeacherGender.setText(row[3])
                self.ui.leTeacherBlood.setText(row[4])
                self.ui.leTeacherAddress.setText(row[5])
                self.ui.leTeacherTelephone.setText(row[6])
                self.ui.leTeacherEmail.setText(row[7])
                self.ui.leTeacherPassword.setText(row[8])

                # Display photo  
                if row[9] is None:
                    pixmap = QPixmap('null.jpg')
                    self.ui.labelPathPhoto.setPixmap(pixmap)
                else:
                    pixmap = QPixmap(row[9])
                    self.ui.labelPathPhoto.setPixmap(pixmap)

                # Disables all line edit widgets
                self. disableWidgets(True)
            else:
                NoRow += 1
                print("This is the first row")

        except Error as e:
            print("Failed to access table")

        finally:
            conn.close() 

    def show_next_row(self):
        global NoRow
        NoRow += 1

        statemenSQL="SELECT * FROM Teacher WHERE teacher_id="+str(NoRow) 
        try:
            conn = sqlite3.connect(db_file) 

            if conn is not None:
                cur = conn.cursor()
                cur.execute(statemenSQL)
                row = cur.fetchone()
                self.ui.leTeacherID.setText(str(row[0]))
                self.ui.leTeacherName.setText(row[1])
                self.ui.deTeacherBirth.setDate(datetime.strptime(row[2], '%m/%d/%Y').date())
                self.ui.leTeacherGender.setText(row[3])
                self.ui.leTeacherBlood.setText(row[4])
                self.ui.leTeacherAddress.setText(row[5])
                self.ui.leTeacherTelephone.setText(row[6])
                self.ui.leTeacherEmail.setText(row[7])
                self.ui.leTeacherPassword.setText(row[8])

                # Display photo
                if row[9] is None:
                    pixmap = QPixmap('null.jpg')
                    self.ui.labelPathPhoto.setPixmap(pixmap)
                else: 
                    pixmap = QPixmap(row[9])
                    self.ui.labelPathPhoto.setPixmap(pixmap)

                # Disables all line edit widgets
                self. disableWidgets(True)

            else:
                NoRow -= 1
                print("This is the last row")

        except Error as e:
            print("Failed to access table")
        finally:
            conn.close()


    def show_last_row(self):
        global NoRow 

        statemenSQL="SELECT * FROM Teacher ORDER BY teacher_id DESC;"
        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor()
                cur.execute(statemenSQL)
                row = cur.fetchone()
                self.ui.leTeacherID.setText(str(row[0]))
                self.ui.leTeacherName.setText(row[1])
                self.ui.deTeacherBirth.setDate(datetime.strptime(row[2], '%m/%d/%Y').date())
                self.ui.leTeacherGender.setText(row[3])
                self.ui.leTeacherBlood.setText(row[4])
                self.ui.leTeacherAddress.setText(row[5])
                self.ui.leTeacherTelephone.setText(row[6])
                self.ui.leTeacherEmail.setText(row[7])
                self.ui.leTeacherPassword.setText(row[8])
                
                # Display photo
                if row[9] is None:
                    pixmap = QPixmap('null.jpg')
                    self.ui.labelPathPhoto.setPixmap(pixmap)
                else:
                    pixmap = QPixmap(row[9])
                    self.ui.labelPathPhoto.setPixmap(pixmap)

                # Disables all line edit widgets
                self. disableWidgets(True)

                NoRow = row[0]

        except Error as e:
            print("Failed to access table")
        finally:
            conn.close()

    def show_teacher_data(self):
        # Clean table
        self.ui.twTeacher.clear()

        # Populate table headers
        col = ['Teacher ID', 'Complete Name', 'Date of Birth',\
                    'Gender', 'Blood Type', 'Address', 'Telephone', 'Email',\
                    'Password', 'Photo Path']
        self.ui.twTeacher.setHorizontalHeaderLabels(col)

        statemenSQL="SELECT * FROM Teacher"
        try:
            conn = sqlite3.connect(db_file)

            if conn is not None:
                cur = conn.cursor() 
                cur.execute(statemenSQL)
                rows = cur.fetchall()

                noRow=0
                for tuple in rows:
                    noCol=0
                    for column in tuple:
                        satuKolom=QTableWidgetItem(str(column))
                        self.ui.twTeacher.setItem(noRow, noCol, satuKolom)
                        noCol+=1
                    noRow+=1

        except Error as e:
            self.ui.twTeacher.clear()
            print(e)
        finally:
            conn.close()
    

if __name__=="__main__":
    import sys
    app = QApplication(sys.argv)
    w = TeacherForm()
    w.show()
    sys.exit(app.exec_())
# QT Designer Python Script

# gui_school.py July 12 - 2021

# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'gui_schooliZRfif.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(1223, 607)
        self.label = QLabel(Dialog)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(10, 10, 131, 21))
        self.label_2 = QLabel(Dialog)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(20, 50, 71, 21))
        self.label_3 = QLabel(Dialog)
        self.label_3.setObjectName(u"label_3")
        self.label_3.setGeometry(QRect(20, 80, 101, 21))
        self.label_4 = QLabel(Dialog)
        self.label_4.setObjectName(u"label_4")
        self.label_4.setGeometry(QRect(20, 110, 91, 21))
        self.label_5 = QLabel(Dialog)
        self.label_5.setObjectName(u"label_5")
        self.label_5.setGeometry(QRect(20, 140, 71, 21))
        self.label_6 = QLabel(Dialog)
        self.label_6.setObjectName(u"label_6")
        self.label_6.setGeometry(QRect(20, 170, 71, 21))
        self.label_7 = QLabel(Dialog)
        self.label_7.setObjectName(u"label_7")
        self.label_7.setGeometry(QRect(20, 250, 61, 21))
        self.label_8 = QLabel(Dialog)
        self.label_8.setObjectName(u"label_8")
        self.label_8.setGeometry(QRect(260, 140, 81, 21))
        self.labelPathPhoto = QLabel(Dialog)
        self.labelPathPhoto.setObjectName(u"labelPathPhoto")
        self.labelPathPhoto.setGeometry(QRect(500, 20, 271, 181))
        self.label_10 = QLabel(Dialog)
        self.label_10.setObjectName(u"label_10")
        self.label_10.setGeometry(QRect(20, 210, 71, 21))
        self.label_11 = QLabel(Dialog)
        self.label_11.setObjectName(u"label_11")
        self.label_11.setGeometry(QRect(560, 260, 71, 21))
        self.leTeacherID = QLineEdit(Dialog)
        self.leTeacherID.setObjectName(u"leTeacherID")
        self.leTeacherID.setGeometry(QRect(120, 50, 113, 20))
        self.leTeacherName = QLineEdit(Dialog)
        self.leTeacherName.setObjectName(u"leTeacherName")
        self.leTeacherName.setGeometry(QRect(120, 80, 171, 20))
        self.leTeacherGender = QLineEdit(Dialog)
        self.leTeacherGender.setObjectName(u"leTeacherGender")
        self.leTeacherGender.setGeometry(QRect(120, 140, 113, 20))
        self.leTeacherBlood = QLineEdit(Dialog)
        self.leTeacherBlood.setObjectName(u"leTeacherBlood")
        self.leTeacherBlood.setGeometry(QRect(330, 140, 113, 20))
        self.leTeacherTelephone = QLineEdit(Dialog)
        self.leTeacherTelephone.setObjectName(u"leTeacherTelephone")
        self.leTeacherTelephone.setGeometry(QRect(120, 210, 161, 20))
        self.leTeacherEmail = QLineEdit(Dialog)
        self.leTeacherEmail.setObjectName(u"leTeacherEmail")
        self.leTeacherEmail.setGeometry(QRect(120, 250, 113, 20))
        self.leTeacherAddress = QLineEdit(Dialog)
        self.leTeacherAddress.setObjectName(u"leTeacherAddress")
        self.leTeacherAddress.setGeometry(QRect(120, 170, 321, 20))
        self.leTeacherPassword = QLineEdit(Dialog)
        self.leTeacherPassword.setObjectName(u"leTeacherPassword")
        self.leTeacherPassword.setGeometry(QRect(650, 260, 131, 20))
        self.pbFirst = QPushButton(Dialog)
        self.pbFirst.setObjectName(u"pbFirst")
        self.pbFirst.setGeometry(QRect(20, 290, 75, 23))
        self.pbPrevious = QPushButton(Dialog)
        self.pbPrevious.setObjectName(u"pbPrevious")
        self.pbPrevious.setGeometry(QRect(230, 290, 75, 23))
        self.pbNext = QPushButton(Dialog)
        self.pbNext.setObjectName(u"pbNext")
        self.pbNext.setGeometry(QRect(480, 290, 75, 23))
        self.pbLast = QPushButton(Dialog)
        self.pbLast.setObjectName(u"pbLast")
        self.pbLast.setGeometry(QRect(710, 290, 75, 23))
        self.pbShowTeacher = QPushButton(Dialog)
        self.pbShowTeacher.setObjectName(u"pbShowTeacher")
        self.pbShowTeacher.setGeometry(QRect(20, 340, 151, 23))
        self.deTeacherBirth = QDateEdit(Dialog)
        self.deTeacherBirth.setObjectName(u"deTeacherBirth")
        self.deTeacherBirth.setGeometry(QRect(120, 110, 110, 22))
        self.twTeacher = QTableWidget(Dialog)
        if (self.twTeacher.columnCount() < 12):
            self.twTeacher.setColumnCount(12)
        if (self.twTeacher.rowCount() < 10):
            self.twTeacher.setRowCount(10)
        self.twTeacher.setObjectName(u"twTeacher")
        self.twTeacher.setGeometry(QRect(20, 370, 711, 161))
        font = QFont()
        font.setFamily(u"MS Shell Dlg 2")
        font.setPointSize(8)
        self.twTeacher.setFont(font)
        self.twTeacher.setAutoFillBackground(True)
        self.twTeacher.setAlternatingRowColors(True)
        self.twTeacher.setRowCount(10)
        self.twTeacher.setColumnCount(12)
        self.twTeacher.horizontalHeader().setVisible(True)
        self.twTeacher.horizontalHeader().setDefaultSectionSize(100)
        self.twTeacher.verticalHeader().setCascadingSectionResizes(False)
        self.twTeacher.verticalHeader().setMinimumSectionSize(20)
        self.twTeacher.verticalHeader().setDefaultSectionSize(20)
        self.twTeacher.verticalHeader().setProperty("showSortIndicator", False)
        self.pbChoosePhotoTeacher = QPushButton(Dialog)
        self.pbChoosePhotoTeacher.setObjectName(u"pbChoosePhotoTeacher")
        self.pbChoosePhotoTeacher.setGeometry(QRect(600, 220, 91, 23))
        self.pbEditTeacher = QPushButton(Dialog)
        self.pbEditTeacher.setObjectName(u"pbEditTeacher")
        self.pbEditTeacher.setGeometry(QRect(340, 340, 101, 23))
        self.pbInsertTeacher = QPushButton(Dialog)
        self.pbInsertTeacher.setObjectName(u"pbInsertTeacher")
        self.pbInsertTeacher.setGeometry(QRect(630, 340, 91, 23))
        self.pbDeleteTeacher = QPushButton(Dialog)
        self.pbDeleteTeacher.setObjectName(u"pbDeleteTeacher")
        self.pbDeleteTeacher.setGeometry(QRect(630, 540, 101, 31))
        self.label_9 = QLabel(Dialog)
        self.label_9.setObjectName(u"label_9")
        self.label_9.setGeometry(QRect(840, 30, 121, 21))
        self.label_12 = QLabel(Dialog)
        self.label_12.setObjectName(u"label_12")
        self.label_12.setGeometry(QRect(910, 80, 51, 20))
        self.label_13 = QLabel(Dialog)
        self.label_13.setObjectName(u"label_13")
        self.label_13.setGeometry(QRect(880, 130, 91, 31))
        self.label_14 = QLabel(Dialog)
        self.label_14.setObjectName(u"label_14")
        self.label_14.setGeometry(QRect(890, 190, 71, 21))
        self.label_15 = QLabel(Dialog)
        self.label_15.setObjectName(u"label_15")
        self.label_15.setGeometry(QRect(890, 280, 71, 20))
        self.leIDClass = QLineEdit(Dialog)
        self.leIDClass.setObjectName(u"leIDClass")
        self.leIDClass.setGeometry(QRect(980, 80, 113, 20))
        self.leIDTeacherClass = QLineEdit(Dialog)
        self.leIDTeacherClass.setObjectName(u"leIDTeacherClass")
        self.leIDTeacherClass.setGeometry(QRect(980, 190, 113, 20))
        self.leIDTeacherClass.setReadOnly(True)
        self.leNameClass = QLineEdit(Dialog)
        self.leNameClass.setObjectName(u"leNameClass")
        self.leNameClass.setGeometry(QRect(980, 230, 113, 20))
        self.cbTeacherNameClass = QComboBox(Dialog)
        self.cbTeacherNameClass.setObjectName(u"cbTeacherNameClass")
        self.cbTeacherNameClass.setGeometry(QRect(980, 130, 181, 31))
        self.pbFirstClass = QPushButton(Dialog)
        self.pbFirstClass.setObjectName(u"pbFirstClass")
        self.pbFirstClass.setGeometry(QRect(850, 330, 75, 23))
        self.pbPreviousClass = QPushButton(Dialog)
        self.pbPreviousClass.setObjectName(u"pbPreviousClass")
        self.pbPreviousClass.setGeometry(QRect(950, 330, 75, 23))
        self.pbNextClass = QPushButton(Dialog)
        self.pbNextClass.setObjectName(u"pbNextClass")
        self.pbNextClass.setGeometry(QRect(1050, 330, 75, 23))
        self.pbLastClass = QPushButton(Dialog)
        self.pbLastClass.setObjectName(u"pbLastClass")
        self.pbLastClass.setGeometry(QRect(1140, 330, 75, 23))
        self.pbShowClass = QPushButton(Dialog)
        self.pbShowClass.setObjectName(u"pbShowClass")
        self.pbShowClass.setGeometry(QRect(850, 360, 75, 23))
        self.pbEditClass = QPushButton(Dialog)
        self.pbEditClass.setObjectName(u"pbEditClass")
        self.pbEditClass.setGeometry(QRect(970, 360, 75, 23))
        self.pbInsertClass = QPushButton(Dialog)
        self.pbInsertClass.setObjectName(u"pbInsertClass")
        self.pbInsertClass.setGeometry(QRect(1100, 360, 75, 23))
        self.pbDeleteClass = QPushButton(Dialog)
        self.pbDeleteClass.setObjectName(u"pbDeleteClass")
        self.pbDeleteClass.setGeometry(QRect(1110, 540, 75, 23))
        self.twClass = QTableWidget(Dialog)
        if (self.twClass.columnCount() < 4):
            self.twClass.setColumnCount(4)
        if (self.twClass.rowCount() < 10):
            self.twClass.setRowCount(10)
        self.twClass.setObjectName(u"twClass")
        self.twClass.setGeometry(QRect(770, 390, 451, 141))
        self.twClass.setFont(font)
        self.twClass.setAutoFillBackground(True)
        self.twClass.setAlternatingRowColors(True)
        self.twClass.setRowCount(10)
        self.twClass.setColumnCount(4)
        self.leCodeClass = QLineEdit(Dialog)
        self.leCodeClass.setObjectName(u"leCodeClass")
        self.leCodeClass.setGeometry(QRect(980, 280, 113, 20))
        self.label_16 = QLabel(Dialog)
        self.label_16.setObjectName(u"label_16")
        self.label_16.setGeometry(QRect(890, 230, 71, 21))

        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))
        self.label.setText(QCoreApplication.translate("Dialog", u"TEACHER INFORMATION", None))
        self.label_2.setText(QCoreApplication.translate("Dialog", u"TEACHER ID", None))
        self.label_3.setText(QCoreApplication.translate("Dialog", u"COMPLETE NAME", None))
        self.label_4.setText(QCoreApplication.translate("Dialog", u"DATE OF BIRTH", None))
        self.label_5.setText(QCoreApplication.translate("Dialog", u"GENDER", None))
        self.label_6.setText(QCoreApplication.translate("Dialog", u"ADDRESS", None))
        self.label_7.setText(QCoreApplication.translate("Dialog", u"EMAIL", None))
        self.label_8.setText(QCoreApplication.translate("Dialog", u"BLOOD TYPE", None))
        self.labelPathPhoto.setText("")
        self.label_10.setText(QCoreApplication.translate("Dialog", u"TELEPHONE", None))
        self.label_11.setText(QCoreApplication.translate("Dialog", u"PASSWORD.", None))
        self.pbFirst.setText(QCoreApplication.translate("Dialog", u"<<", None))
        self.pbPrevious.setText(QCoreApplication.translate("Dialog", u"<", None))
        self.pbNext.setText(QCoreApplication.translate("Dialog", u">", None))
        self.pbLast.setText(QCoreApplication.translate("Dialog", u">>", None))
        self.pbShowTeacher.setText(QCoreApplication.translate("Dialog", u"Show All Teachers Data", None))
        self.pbChoosePhotoTeacher.setText(QCoreApplication.translate("Dialog", u"Choose Photo", None))
        self.pbEditTeacher.setText(QCoreApplication.translate("Dialog", u"Edit Teacher", None))
        self.pbInsertTeacher.setText(QCoreApplication.translate("Dialog", u"Insert Teacher", None))
        self.pbDeleteTeacher.setText(QCoreApplication.translate("Dialog", u"REMOVE DATA", None))
        self.label_9.setText(QCoreApplication.translate("Dialog", u"CLASS INFORMATION", None))
        self.label_12.setText(QCoreApplication.translate("Dialog", u"CLASS ID", None))
        self.label_13.setText(QCoreApplication.translate("Dialog", u"TEACHERS NAME", None))
        self.label_14.setText(QCoreApplication.translate("Dialog", u"TEACHER ID", None))
        self.label_15.setText(QCoreApplication.translate("Dialog", u"CLASS CODE", None))
        self.leNameClass.setText("")
        self.pbFirstClass.setText(QCoreApplication.translate("Dialog", u"<<", None))
        self.pbPreviousClass.setText(QCoreApplication.translate("Dialog", u"<", None))
        self.pbNextClass.setText(QCoreApplication.translate("Dialog", u">", None))
        self.pbLastClass.setText(QCoreApplication.translate("Dialog", u">>", None))
        self.pbShowClass.setText(QCoreApplication.translate("Dialog", u"Show Class", None))
        self.pbEditClass.setText(QCoreApplication.translate("Dialog", u"Edit Class", None))
        self.pbInsertClass.setText(QCoreApplication.translate("Dialog", u"Insert Class", None))
        self.pbDeleteClass.setText(QCoreApplication.translate("Dialog", u"Delete Class", None))
        self.leCodeClass.setText("")
        self.label_16.setText(QCoreApplication.translate("Dialog", u"CLASS NAME", None))
    # retranslateUi
Which argument is causing the problem; the str or the flag. I would ask Python for the answer.
                    print(row[4], type(str(row[4])), QtCore.Qt.MatchedFixedString, type(QtCore.Qt.MatchFixedString))
                    index = self.ui.cbTeacherNameClass.findText(str(row[4]), QtCore.Qt.MatchFixedString)
I don't think "MatchFixedString" is allowed. According to this documentation for Python QT:

https://doc.qt.io/qtforpython/PySide6/Qt...x.findText

It at least implies that valid flags are
Quote:Qt.MatchExactly|Qt.MatchCaseSensitive
After a great deal (days) of debugging my code it was a simple fix. (I believe I learned a lot in the process!). I added this line "from PySide2 import QtCore" to the top of my code. For some reason "from PyQt5 import QtCore, QtGui, QtWidgets" won't work. Thanks for your input.