1

I have written a python 3.4 code which uses pyqt4 GUI modules but when i run the module it does not show anything kindly help

import sys
from PyQt4 import QtGui,QtCore

class window(QtGui.QMainWindow):

    def _init_(self):
        super(Window, self)._init_()
        self.setGeometry(50,50,500,300)
        self.setWindowTitle("Tallman Server")
        self.setWindowIcon(QtGui.QIcon("tracking.png"))
        self.home()
    def home():
            btn=QtGui.QPushButton("Quit",self)
            btn.clicked.connect(QtCore.QCoreApplication.instance().quit)
            self.show()


def run():    
         app=QtGui.QApplication(sys.argv)
         GUI=window()
         sys.exit(app.exec_())

run()

1 Answer 1

1

Firstly, the function's name is __init__ instead of _init_. Secondly, you have to add the self parameter to home().

Those changes will solve your problem.

Modified code:

import sys
from PyQt4 import QtGui,QtCore

class window(QtGui.QMainWindow):

    def __init__(self):
        super(window, self).__init__()
        self.setGeometry(50,50,500,300)
        self.setWindowTitle("Tallman Server")
        self.setWindowIcon(QtGui.QIcon("tracking.png"))
        self.home()
    def home(self):
        btn=QtGui.QPushButton("Quit",self)
        btn.clicked.connect(QtCore.QCoreApplication.instance().quit)
        self.show()


def run():
    app=QtGui.QApplication(sys.argv)
    GUI=window()
    sys.exit(app.exec_())

run()
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the great help am new in pyqt neve knew small errors could make the program not work.
@tallman: __init__ and self are part of python's object oriented features and have nothing to do with pyqt. I suggest you make yourself familiar with classes, e.g. this documentation explains it. Otherwise you'll run into similar problems in the future

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.