Planned maintenance: From Sunday 8th December 10:00 CET there will be changes to try and solve the caching issues that have been experienced. If anyone has a problem connecting after this period then please PM @AndyS or any of the moderators.

Need some help

  • Hi all

    I have a conception with a technical follow up question around PyQt5, Python 3 and Postgres.

    I have a Postgres DB setup and populated with tables and information. Now my aim is to get my front end ( in Pyqt5 ) to talk to the DB and retrieve data. Now in Python, I know how to do that ( not displayed in the code below ).

    My question is that if you run the main code you will get the GUI pop up. ( I can't upload a picture )

    What needs to happen is that the player must be able to enter data that writes back to the DB and I want to add drop-down menus that populate with the information inside the DB.

    Form an architecture persp0ective I want to know if I am moving in the right direction?

    From a coding perspective how the hell do I link the text field to save back to the DB?

    I know this is a lot of questions but I could really need some pro's insight

    import sys
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5 import *

    class Window(QMainWindow):
    def init(self):

        self.title = "New Player Screen"
        self.left = 100 = 100
        self.width = 700
        self.height = 540
        self.textbox = "User input"
        name = QtWidgets.QLabel(self)
        name.setText("Character Name :")
        name.setStyleSheet("font: 10pt CODE")
        self.textbox = QLineEdit(self)
        close_button = QPushButton(" Close ",self)
        close_button.setToolTip("<h3>This is my click button")
    def InitUI(self):
    def Close(self):

    App = QApplication(sys.argv)
    window = Window()

  • First off regardless of the coding language you should follow the MVC (Model-View-Controller) methodology of coding which basically divorces the front-end (View) from the back-end (Model) by putting in a middle interpreter layer (Controller). Why do this well first it has the benefit of separating functionality and focusing each element on what it does best. The GUI (View) is best for handling the user interface and not very good with dealing with the data, while the Database (Model) is best for handling the data and is not very good with handling the user interface. The Controller is just the method for moving the data from the View to Model. This also has a secondary benefit if you ever change the back-end with a different database engine the only thing that is effected is the Model and maybe a bit of the Controller the GUI is essentially untouched and vice-versa if you wish to change the front-end the only thing that really changes is the front-end since all the API calls to the middle-tier would essentially remain the same. Further should the business logic affecting the data occur that is generally dealt with within the Controller or the Database depending on the implementation of the business logic. For instance data validation and manipulation generally takes place within the Controller layer making sure that no bad-data gets into the database which is always a nightmare and something that happens often if you directly tie the front-end into the back-end.

    So in short use pyqt5 to handle your front-end GUI and use python to handle your interface to your database (validating and moving the data to the database) and let the database do what its best at doing - handling the data with storage and stored-procedures, triggers, etc...

    I hope that helps

Log in to reply