Python Forum
using qt with classes basic window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using qt with classes basic window
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 341 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,619 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 8,974 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  Show second window using classes iFunKtion 2 3,708 Feb-10-2017, 12:50 PM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020