How to implement a simple button in PyQt

I want to implement a simple button in PyQt that prints "Hello world" when clicked. How can i do this?

I am a real newbie to PyQt.

+6
source share
1 answer

If you are new to PyQt4, there are some useful PyQt Wiki guides to get you started.

But at the same time, here is your Hello World example:

from PyQt4 import QtGui, QtCore class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.button = QtGui.QPushButton('Test', self) self.button.clicked.connect(self.handleButton) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.button) def handleButton(self): print ('Hello World') if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_()) 
+20
source

Source: https://habr.com/ru/post/905343/


All Articles