我在学Python。我对它不熟悉。你知道吗
http://zetcode.com/gui/pyqt4/firstprograms/
现在,我正在试着做一个锻炼用的计算器。我修改了一点示例程序。但我错了。你知道吗
Traceback (most recent call last):
File "customCalculatorGUI.py", line 50, in buttonClicked
self.showMessage(sender.text() + ' was pressed')
AttributeError: 'Example' object has no attribute 'showMessage'
import sys
from PyQt4 import QtGui, QtCore
"""
ZetCode PyQt4 tutorial
In this example, we create a skeleton
of a calculator using a QtGui.QGridLayout.
author: Jan Bodnar
website: zetcode.com
last edited: July 2014
"""
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
grid = QtGui.QGridLayout()
self.setLayout(grid)
names = ['Cls', 'Bck', '', 'Close',
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+']
positions = [(i,j) for i in range(5) for j in range(4)]
for position, name in zip(positions, names):
if name == '':
continue
button = QtGui.QPushButton(name)
button.clicked.connect(self.buttonClicked)
grid.addWidget(button, *position)
self.move(300, 150)
self.setWindowTitle('Calculator')
self.show()
def buttonClicked(self):
sender = self.sender()
self.showMessage(sender.text() + ' was pressed')
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我查过了 http://qt-project.org/doc/qt-4.8/qwidget.html
没有showMessage类。 但现在,我不知道如何显示信息。你知道吗
如果我想在单击按钮时在状态栏上显示消息。 我该怎么做?你知道吗
检查this。您需要使用
statusBar
的对象,并对该对象调用showMessage
。你知道吗做了这么长时间,所以这不是一个编码帮助。但这会指引你前进的方向。看看这是否有用?你知道吗
相关问题 更多 >
编程相关推荐