Python Forum
using qt with classes basic window - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: using qt with classes basic window (/thread-1948.html)



using qt with classes basic window - iFunKtion - Feb-06-2017

Hi there,

really struggling here, so I am going back to basics to try and work out why none of this is working. So I can create a complete application and it will work, but at the expense of readable reusable code.

How can I get a simple window to work please:
#!/usr/bin/python3

import sys
from PyQt4 import QtGui, QtCore

class Window(QtGui.QDialog):
     '''top level window'''
     def __init__(self, parent=None):
          QtGui.QWidget.__init__(self, parent)
          self.setGeometry(0, 0, 1920, 1080)
          self.home()

     def home(self):
          '''Defines the main application view for data input'''
          self.lbl = QtGui.QLabel("Hello World", self)
          self.lbl.setGeometry(QtCore.QRect(80, 30, 1161, 101))
          self.show

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main_window = Window()
    sys.exit(app.exec_())
What am I doing wrong, Nothing shows up when run, and the only way to get out of it is to close the Terminal window as even ctrl-C won't stop the script.

Ok after going through my original code that worked and commenting out over 500 lines one by one, it appears that I missed off the parentheses after self.show it should be:
self.show()
Solved.