So I have written this PyQt5 code and could not fathom why is home
not being executed when I click on the download button. On the other hand if I move the contents of the home
to __init__
it is working fine. What exactly is going wrong here and how to rectify it?
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import Qt
class GUI(QMainWindow):
def __init__(self):
super(GUI, self).__init__()
self.setGeometry(50, 50, 800, 500)
self.setWindowTitle('App')
self.setWindowIcon(QIcon('icon.ico'))
backgroundImage = QImage('back.jpg')
backgroundScaledImage = backgroundImage.scaled(QSize(800,500))
palette = QPalette()
palette.setBrush(10, QBrush(backgroundScaledImage))
self.setPalette(palette)
self.progress = QProgressBar(self)
self.progress.setGeometry(20, 30, 300, 20)
self.btn = QPushButton('Download', self)
self.btn.move(200,120)
self.btn.clicked.connect(self.home)
#self.home()
QApplication.setStyle(QStyleFactory.create('plastique'))
self.show()
def home(self):
print('whoa')
# Create textbox
self.textbox = QLineEdit(self)
self.textbox.move(200, 200)
self.textbox.resize(280,40)
# Create a button in the window
self.button = QPushButton('Show text', self)
self.button.move(20,80)
self.show()
When I uncomment the line #self.home()
or directly put the code at that place the code is working as expected. But when I click the Download
button nothing is happening.