Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 PyQt5 form not displaying my data from SQLite3 Database
#1
Good afternoon;
I am fairly new to Python. I am attempting to make a personal classic Movie database. I am using PyQt5, Python 3.7 and Sqlite3. My form will display but there is not any data showing. My .db is in the same directory of my .ui and .py file. Thank you for any help that can be provided. Here is the coding.

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

# Form implementation generated from reading ui file 'Classic.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.Title = QtWidgets.QLabel(self.centralwidget)
        self.Title.setGeometry(QtCore.QRect(10, 10, 31, 16))
        self.Title.setObjectName("Title")
        self.Year = QtWidgets.QLabel(self.centralwidget)
        self.Year.setGeometry(QtCore.QRect(500, 10, 31, 16))
        self.Year.setObjectName("Year")
        self.Rating = QtWidgets.QLabel(self.centralwidget)
        self.Rating.setGeometry(QtCore.QRect(10, 60, 31, 16))
        self.Rating.setObjectName("Rating")
        self.Length = QtWidgets.QLabel(self.centralwidget)
        self.Length.setGeometry(QtCore.QRect(130, 60, 41, 16))
        self.Length.setObjectName("Length")
        self.Genre = QtWidgets.QLabel(self.centralwidget)
        self.Genre.setGeometry(QtCore.QRect(260, 60, 47, 13))
        self.Genre.setObjectName("Genre")
        self.Summary = QtWidgets.QLabel(self.centralwidget)
        self.Summary.setGeometry(QtCore.QRect(10, 150, 47, 13))
        self.Summary.setObjectName("Summary")
        self.Directors = QtWidgets.QLabel(self.centralwidget)
        self.Directors.setGeometry(QtCore.QRect(10, 270, 47, 13))
        self.Directors.setObjectName("Directors")
        self.Actors = QtWidgets.QLabel(self.centralwidget)
        self.Actors.setGeometry(QtCore.QRect(10, 310, 47, 13))
        self.Actors.setObjectName("Actors")
        self.Title_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Title_2.setGeometry(QtCore.QRect(40, 10, 451, 20))
        self.Title_2.setObjectName("Title_2")
        self.Year_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Year_2.setGeometry(QtCore.QRect(540, 10, 91, 20))
        self.Year_2.setObjectName("Year_2")
        self.Rating_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Rating_2.setGeometry(QtCore.QRect(50, 60, 71, 20))
        self.Rating_2.setObjectName("Rating_2")
        self.Length_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Length_2.setGeometry(QtCore.QRect(170, 60, 71, 20))
        self.Length_2.setObjectName("Length_2")
        self.Genre_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Genre_2.setGeometry(QtCore.QRect(300, 60, 361, 20))
        self.Genre_2.setObjectName("Genre_2")
        self.Summary_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Summary_2.setGeometry(QtCore.QRect(70, 150, 591, 101))
        self.Summary_2.setObjectName("Summary_2")
        self.Directors_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Directors_2.setGeometry(QtCore.QRect(70, 270, 591, 20))
        self.Directors_2.setObjectName("Directors_2")
        self.Actors_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.Actors_2.setGeometry(QtCore.QRect(70, 310, 591, 20))
        self.Actors_2.setObjectName("Actors_2")
        self.Quit = QtWidgets.QPushButton(self.centralwidget)
        self.Quit.setGeometry(QtCore.QRect(660, 400, 75, 23))
        self.Quit.setObjectName("Quit")
        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", "Classics"))
        self.Title.setText(_translate("MainWindow", "Title"))
        self.Year.setText(_translate("MainWindow", "Year"))
        self.Rating.setText(_translate("MainWindow", "Rating"))
        self.Length.setText(_translate("MainWindow", "Length"))
        self.Genre.setText(_translate("MainWindow", "Genre"))
        self.Summary.setText(_translate("MainWindow", "Summary"))
        self.Directors.setText(_translate("MainWindow", "Directors"))
        self.Actors.setText(_translate("MainWindow", "Actors"))
        self.Quit.setText(_translate("MainWindow", "Quit"))


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_())

    import _sqlite3
    from _sqlite3 import Error

    # Connecting to the database file
    def create_connection(patrick):
        conn = None
        try:
            conn = _sqlite3.connect('patrick.db')
        except Error as e:
            print(e)
        return conn

    def select_all_Films(conn):
        cur = conn.cursor()
        cur.execute("SELECT * FROM Film")

        rows = cur.fetchall()

        for row in rows:
            print(row)

    if __name__ == '__main__':
        main()





Quote
#2
Okay before we get started on deciphering what you got I want to state -- first you are hurting yourself by using Designer code for you Gui as a pure Python-Qt (aka PyQt5 or PySide2) version created as it was meant to be used is just as quick and simple once you have learned how it works and what you end up with is not only code you understand but a better understanding of how Qt works.

Next when it comes to your Database and your Gui -- I hope that you are using MVC methodology but I expecting that you are not and that is another major issue that will cause you much pain.

So let me know if you want to address both of these things and learn how to do it properly so that you pain is minimized -- coding always comes with a little pain but no pain no gain ;-)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Displaying Data from a database and run a function when clicked? PythonNPC 1 106 Mar-11-2020, 08:16 PM
Last Post: Larz60+
  [PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget YoshikageKira 6 317 Jan-02-2020, 04:32 PM
Last Post: Denni
  [PyQt] Send data between windows Pyqt5 and Qt Designer kkonrad002 8 1,352 Sep-05-2019, 02:25 PM
Last Post: Denni
  [Tkinter] TKINTER quiz using sqlite3 database hezza_23 44 4,452 Apr-15-2019, 11:46 AM
Last Post: hezza_23
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 535 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  [Tkinter] I need to know how to put my SQLite3 data into a Treeview Thename921 1 2,000 Jan-12-2019, 10:26 PM
Last Post: Larz60+
  [PyQt5] get all row data from tableview model cpuin 0 2,150 Mar-07-2018, 12:28 PM
Last Post: cpuin

Forum Jump:


Users browsing this thread: 1 Guest(s)