Reputation: 71
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()
Upvotes: 1
Views: 252
Reputation: 1856
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()
Upvotes: 1