Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

When I click Run I see nothing



  • Hi everyone! I am a newbie.
    I have designed a GUI using QtDesigner and it works well when i click CTRL+R.
    Untitled.png
    But when Run GUI from Pycharm I see this
    Untitled2.png

    What can be the reason of this. Here is the code (this just GUI code. I converted .ui file to .py file):

    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'view.ui'
    #
    # Created by: PyQt5 UI code generator 5.6
    #
    # WARNING! All changes made in this file will be lost!
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class Ui_Form(object):
        def setupUi(self, Form):
            Form.setObjectName("Form")
            Form.setWindowModality(QtCore.Qt.NonModal)
            Form.resize(752, 600)
            self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.frame = QtWidgets.QFrame(Form)
            self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame.setObjectName("frame")
            self.gridLayout_4 = QtWidgets.QGridLayout(self.frame)
            self.gridLayout_4.setObjectName("gridLayout_4")
            self.frame_2 = QtWidgets.QFrame(self.frame)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_2.sizePolicy().hasHeightForWidth())
            self.frame_2.setSizePolicy(sizePolicy)
            self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_2.setObjectName("frame_2")
            self.gridLayout = QtWidgets.QGridLayout(self.frame_2)
            self.gridLayout.setObjectName("gridLayout")
            self.frame_5 = QtWidgets.QFrame(self.frame_2)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_5.sizePolicy().hasHeightForWidth())
            self.frame_5.setSizePolicy(sizePolicy)
            self.frame_5.setMaximumSize(QtCore.QSize(16777215, 110))
            self.frame_5.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_5.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_5.setObjectName("frame_5")
            self.verticalLayout = QtWidgets.QVBoxLayout(self.frame_5)
            self.verticalLayout.setObjectName("verticalLayout")
            self.pushButton = QtWidgets.QPushButton(self.frame_5)
            self.pushButton.setObjectName("pushButton")
            self.verticalLayout.addWidget(self.pushButton)
            self.gridLayout.addWidget(self.frame_5, 0, 0, 1, 1)
            self.frame_6 = QtWidgets.QFrame(self.frame_2)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_6.sizePolicy().hasHeightForWidth())
            self.frame_6.setSizePolicy(sizePolicy)
            self.frame_6.setMaximumSize(QtCore.QSize(300, 300))
            self.frame_6.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_6.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_6.setObjectName("frame_6")
            self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.frame_6)
            self.horizontalLayout_4.setObjectName("horizontalLayout_4")
            self.label = QtWidgets.QLabel(self.frame_6)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
            self.label.setSizePolicy(sizePolicy)
            self.label.setMaximumSize(QtCore.QSize(300, 300))
            self.label.setFrameShape(QtWidgets.QFrame.Box)
            self.label.setText("")
            self.label.setObjectName("label")
            self.horizontalLayout_4.addWidget(self.label)
            self.gridLayout.addWidget(self.frame_6, 1, 0, 1, 1)
            self.frame_7 = QtWidgets.QFrame(self.frame_2)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_7.sizePolicy().hasHeightForWidth())
            self.frame_7.setSizePolicy(sizePolicy)
            self.frame_7.setMinimumSize(QtCore.QSize(27, 25))
            self.frame_7.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_7.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_7.setObjectName("frame_7")
            self.gridLayout.addWidget(self.frame_7, 2, 0, 1, 1)
            self.gridLayout_4.addWidget(self.frame_2, 0, 0, 1, 1)
            self.frame_3 = QtWidgets.QFrame(self.frame)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_3.sizePolicy().hasHeightForWidth())
            self.frame_3.setSizePolicy(sizePolicy)
            self.frame_3.setMaximumSize(QtCore.QSize(400, 750))
            self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_3.setObjectName("frame_3")
            self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame_3)
            self.verticalLayout_3.setObjectName("verticalLayout_3")
            self.frame_8 = QtWidgets.QFrame(self.frame_3)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_8.sizePolicy().hasHeightForWidth())
            self.frame_8.setSizePolicy(sizePolicy)
            self.frame_8.setMaximumSize(QtCore.QSize(16777215, 200))
            self.frame_8.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_8.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_8.setObjectName("frame_8")
            self.gridLayout_2 = QtWidgets.QGridLayout(self.frame_8)
            self.gridLayout_2.setObjectName("gridLayout_2")
            self.label_2 = QtWidgets.QLabel(self.frame_8)
            self.label_2.setFrameShape(QtWidgets.QFrame.Box)
            self.label_2.setText("")
            self.label_2.setObjectName("label_2")
            self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1)
            self.verticalLayout_3.addWidget(self.frame_8)
            self.frame_9 = QtWidgets.QFrame(self.frame_3)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_9.sizePolicy().hasHeightForWidth())
            self.frame_9.setSizePolicy(sizePolicy)
            self.frame_9.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_9.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_9.setObjectName("frame_9")
            self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.frame_9)
            self.verticalLayout_4.setObjectName("verticalLayout_4")
            self.label_3 = QtWidgets.QLabel(self.frame_9)
            self.label_3.setObjectName("label_3")
            self.verticalLayout_4.addWidget(self.label_3)
            self.verticalLayout_3.addWidget(self.frame_9)
            self.frame_10 = QtWidgets.QFrame(self.frame_3)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_10.sizePolicy().hasHeightForWidth())
            self.frame_10.setSizePolicy(sizePolicy)
            self.frame_10.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_10.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_10.setObjectName("frame_10")
            self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.frame_10)
            self.verticalLayout_5.setObjectName("verticalLayout_5")
            self.scrollArea = QtWidgets.QScrollArea(self.frame_10)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.scrollArea.sizePolicy().hasHeightForWidth())
            self.scrollArea.setSizePolicy(sizePolicy)
            self.scrollArea.setMinimumSize(QtCore.QSize(0, 50))
            self.scrollArea.setWidgetResizable(True)
            self.scrollArea.setObjectName("scrollArea")
            self.scrollAreaWidgetContents = QtWidgets.QWidget()
            self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 254, 69))
            self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
            self.scrollArea.setWidget(self.scrollAreaWidgetContents)
            self.verticalLayout_5.addWidget(self.scrollArea)
            self.textEdit = QtWidgets.QTextEdit(self.frame_10)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.textEdit.sizePolicy().hasHeightForWidth())
            self.textEdit.setSizePolicy(sizePolicy)
            self.textEdit.setObjectName("textEdit")
            self.verticalLayout_5.addWidget(self.textEdit)
            self.verticalLayout_3.addWidget(self.frame_10)
            self.gridLayout_4.addWidget(self.frame_3, 0, 1, 1, 1)
            self.frame_4 = QtWidgets.QFrame(self.frame)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_4.sizePolicy().hasHeightForWidth())
            self.frame_4.setSizePolicy(sizePolicy)
            self.frame_4.setMaximumSize(QtCore.QSize(400, 750))
            self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_4.setObjectName("frame_4")
            self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.frame_4)
            self.verticalLayout_7.setObjectName("verticalLayout_7")
            self.frame_11 = QtWidgets.QFrame(self.frame_4)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_11.sizePolicy().hasHeightForWidth())
            self.frame_11.setSizePolicy(sizePolicy)
            self.frame_11.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_11.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_11.setObjectName("frame_11")
            self.gridLayout_3 = QtWidgets.QGridLayout(self.frame_11)
            self.gridLayout_3.setObjectName("gridLayout_3")
            self.label_4 = QtWidgets.QLabel(self.frame_11)
            self.label_4.setFrameShape(QtWidgets.QFrame.Box)
            self.label_4.setText("")
            self.label_4.setObjectName("label_4")
            self.gridLayout_3.addWidget(self.label_4, 0, 0, 1, 1)
            self.verticalLayout_7.addWidget(self.frame_11)
            self.frame_12 = QtWidgets.QFrame(self.frame_4)
            self.frame_12.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_12.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_12.setObjectName("frame_12")
            self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.frame_12)
            self.horizontalLayout_3.setObjectName("horizontalLayout_3")
            self.label_5 = QtWidgets.QLabel(self.frame_12)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.label_5.sizePolicy().hasHeightForWidth())
            self.label_5.setSizePolicy(sizePolicy)
            self.label_5.setObjectName("label_5")
            self.horizontalLayout_3.addWidget(self.label_5)
            self.verticalLayout_7.addWidget(self.frame_12)
            self.frame_13 = QtWidgets.QFrame(self.frame_4)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_13.sizePolicy().hasHeightForWidth())
            self.frame_13.setSizePolicy(sizePolicy)
            self.frame_13.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame_13.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame_13.setObjectName("frame_13")
            self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.frame_13)
            self.verticalLayout_6.setObjectName("verticalLayout_6")
            self.scrollArea_2 = QtWidgets.QScrollArea(self.frame_13)
            self.scrollArea_2.setWidgetResizable(True)
            self.scrollArea_2.setObjectName("scrollArea_2")
            self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
            self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 249, 69))
            self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
            self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_2)
            self.verticalLayout_6.addWidget(self.scrollArea_2)
            self.textEdit_2 = QtWidgets.QTextEdit(self.frame_13)
            self.textEdit_2.setObjectName("textEdit_2")
            self.verticalLayout_6.addWidget(self.textEdit_2)
            self.verticalLayout_7.addWidget(self.frame_13)
            self.gridLayout_4.addWidget(self.frame_4, 0, 2, 1, 1)
            self.horizontalLayout.addWidget(self.frame)
    
            self.retranslateUi(Form)
            QtCore.QMetaObject.connectSlotsByName(Form)
    
        def retranslateUi(self, Form):
            _translate = QtCore.QCoreApplication.translate
            Form.setWindowTitle(_translate("Form", "Form"))
            self.pushButton.setText(_translate("Form", "Find Detects"))
            self.label_3.setText(_translate("Form", "Size of defects on the lower part"))
            self.label_5.setText(_translate("Form", "Size of defects on the upper parts"))
    
    
    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_())
    
    
    


  • @hernancrespo89
    You're sure no PyCharm window is showing any warning/output?
    You have set up PyCharm to use the right Python interpreter?
    What about cding to the source directory and trying python view.py (or python3 view.py if you're Linux)?



  • @JonB said in When I click Run I see nothing:

    @hernancrespo89
    You're sure no PyCharm window is showing any warning/output?

    Yes I am sure

    You have set up PyCharm to use the right Python interpreter?

    I set up Pycharm already?.I am using python.exe as interpreter

    What about cding to the source directory and trying python view.py (or python3 view.py if you're Linux)?

    I tried

    pyuic5 -x python view.ui -o python view.py
    

    and I see this error:
    one input ui-file must be specified



  • @hernancrespo89
    I suggested you try to run your .py file, not pyuic5 ... -o your.py.



  • @hernancrespo89
    I'm still a touch perplexed at the possible absence of one line in the code you show.

    At the end of setupUi(), just before the self.retranslateUi(Form):

            self.horizontalLayout.addWidget(self.frame)
    
            self.retranslateUi(Form)
    

    I was expecting to see something which set the Form QWidget's to have self.horizontalLayout as its layout. Without that you would get the frame of the widget with title but not content, just as your screenshot shows.

    EDIT OK, I see self.horizontalLayout = QtWidgets.QHBoxLayout(Form) early on, that should do it.

    OK, it's time to crack open the (excellent) PyCharm debugger and see where stepping through your code takes you. Any time you spend learning it now will reward you in spades in later life :)



  • This post is deleted!


  • @JonB said in When I click Run I see nothing:

    @hernancrespo89
    I suggested you try to run your .py file, not pyuic5 ... -o your.py.

    I run .py file but I wanted to show codes, so I have added them to post.



  • @JonB said in When I click Run I see nothing:

    OK, it's time to crack open the (excellent) PyCharm debugger and see where stepping through your code takes you. Any time you spend learning it now will reward you in spades in later life :)

    Thanks for all your answers. But first time it GUI shows up, I see that blank. So, I am unable to understand which Widget causes problem. :( how can I debug itUntitled.png



  • @hernancrespo89
    Just for now, comment out all the stuff after loadUi(...). Let's just see whether something you are doing prevents the widget from showing properly. To start with all you're supposed to be trying is seeing how the code you originally showed is working.

    Also what is that loadUi() about? I thought you were testing the file you showed was generated, it's a standalone python program?

    Are you somehow using both pyuic5 and ui.loadUi()? https://stackoverflow.com/questions/52471705/why-in-pyqt5-should-i-use-pyuic5-and-not-uic-loaduimy-ui

    If you are currently generating, say, view.py (as shown earlier) from view.ui, as I said you should at least try running python view.py.



  • @JonB said in When I click Run I see nothing:

    @hernancrespo89
    Just for now, comment out all the stuff after loadUi(...). Let's just see whether something you are doing prevents the widget from showing properly. To start with all you're supposed to be trying is seeing how the code you originally showed is working.

    I commented out all the stuff after loadUi and I see still blank GUI.

    Also what is that loadUi() about? I thought you were testing the file you showed was generated, it's a standalone python program?

    Are you somehow using both pyuic5 and ui.loadUi()? https://stackoverflow.com/questions/52471705/why-in-pyqt5-should-i-use-pyuic5-and-not-uic-loaduimy-ui

    No, I am using, only ui.loadUi(). I just wanted to show code behind my GUI and I used pyuic5 for that purpose. (just for posting here) . I have a main.py and view.py i call my GUI using ui.loadUi() in view.py

    If you are currently generating, say, view.py (as shown earlier) from view.ui, as I said you should at least try running python view.py.

    So, I am not geberating view.py


  • Lifetime Qt Champion

    Hi,

    I just copy pasted your code and ran it directly in a virtualenv with the latest PyQt5 installed through and worked properly (on macOS).



  • @SGaist
    But the OP is saying that is not his code, he isn't using pyuic...!
    He is using loadUi() on his ,ui file instead.... :)


  • Lifetime Qt Champion

    @JonB I meant the code from his original post.



  • @SGaist
    I know! But he only posted it as an example to illustrate his .ui file :)

    I suggested he verify the pyuic output he posted worked as standalone.

    So his question is why it doesn't work from uic.loadUi(). Assuming that's what loadUi() calls.



  • @JonB said in When I click Run I see nothing:

    @SGaist
    I know! But he only posted it as an example to illustrate his .ui file :)

    I suggested he verify the pyuic output he posted worked as standalone.

    So his question is why it doesn't work from uic.loadUi(). Assuming that's what loadUi() calls.

    Do you mean this by saying standalone?

    from PyQt5.QtWidgets import *
    from PyQt5.uic import loadUi
    
    class loadUi_example(QMainWindow):
    
        def __init__(self):
            super().__init__()
            loadUi("view.ui", self)
    
    app = QApplication([])
    window = loadUi_example()
    window.show()
    app.exec_()
    


  • This post is deleted!


  • @SGaist said in When I click Run I see nothing:

    Hi,

    I just copy pasted your code and ran it directly in a virtualenv with the latest PyQt5 installed through and worked properly (on macOS).

    Thank you, yes I can work it, too. But when i try to import it using uic.loadUi(). I see blank screen.


Log in to reply