【发布时间】:2012-02-04 11:30:45
【问题描述】:
我想在 PyQt 中实现一个简单的按钮,单击它会打印“Hello world”。我该怎么做?
我是 PyQt 的真正新手。
【问题讨论】:
-
尝试阅读一些tutorials
标签: python user-interface button pyqt signals-slots
我想在 PyQt 中实现一个简单的按钮,单击它会打印“Hello world”。我该怎么做?
我是 PyQt 的真正新手。
【问题讨论】:
标签: python user-interface button pyqt signals-slots
如果您是 PyQt 的新手,PyQt Wiki 上有一些有用的教程可以帮助您入门。但与此同时,这是您的“Hello World”示例:
from PyQt5 import QtWidgets, QtCore
class Window(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.button = QtWidgets.QPushButton('Test')
self.button.clicked.connect(self.handleButton)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.button)
def handleButton(self):
print('Hello World')
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
【讨论】:
Failed to load platform plugin "xcb". Available platforms are "linuxfb" and "minimal". Do you know why? I am running from with the latest stable Python, IPython, Qt5 and snapshot from PyQt4