我开始使用Python 3在PyQt5中创建GUI。单击按钮我想运行“randomint”函数并将返回的整数显示到名为“lcd”的QLCDNumber ”。PyQt5按钮来运行功能和更新LCD
这里是我的代码:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLCDNumber
from random import randint
class Window(QWidget):
def __init__(self):
super().__init__()
self.initui()
def initui(self):
lcd = QLCDNumber(self)
button = QPushButton('Generate', self)
button.resize(button.sizeHint())
layout = QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(button)
self.setLayout(layout)
button.clicked.connect(lcd.display(self.randomint()))
self.setGeometry(300, 500, 250, 150)
self.setWindowTitle('Rand Integer')
self.show()
def randomint(self):
random = randint(2, 99)
return random
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Window()
sys.exit(app.exec_())
我得到的输出:
TypeError: argument 1 has unexpected type 'NoneType'
我怎样才能获得LCD显示功能,从 “randomint” 输出?
这样做。感谢您的解释! –