如何实现在PyQt的一个简单的按钮 [英] How to implement a simple button in PyQt

查看:537
本文介绍了如何实现在PyQt的一个简单的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现PyQt的一个简单的按钮,打印Hello World的点击时。我该怎么做?

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

我在PyQt的一个真正的新手。我使用的Fedora。

I am a real newbie in PyQt. I am using fedora.

感谢所有

推荐答案

如果你是新来PyQt4的,也有对的 PyQt的维基来让你开始。

If you're new to PyQt4, there are some useful tutorials on the PyQt Wiki to get you started.

不过在此之前,这里是你的Hello World的例子:

But in the meantime, here's 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_())

这篇关于如何实现在PyQt的一个简单的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆