DownTheBasket DownTheBasket - 1 year ago 165
Python Question

PyQt5 PushButton not showing

This is the code I am using and the button doesn't show and it only shows a blank window. There is no error in the console.

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *


import sys

def start():
app = QApplication(sys.argv)
w = QWidget()
w.resize(128,102)
w.move(0, 0)
w.setWindowTitle('Simple')
btn = QtWidgets.QPushButton("Hi")
btn.move(50, 50)
btn.resize(btn.sizeHint())
w.show()

sys.exit(app.exec_())

start()


This is the window it shows
pic

Answer Source

Try passing the parent argument to the constructor. The parent argument causes the button to be owned by Qt, not PyQt. btn = QtWidgets.QPushButton("Hi", w) should work.