datetime:2019/5/21 16:59
author:nzb
生成随机数
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QGroupBox, \
QHBoxLayout, QPushButton, QVBoxLayout, QSpinBox, QLCDNumber
from PyQt5.QtWidgets import QDial
from PyQt5 import QtGui, QtCore
from PyQt5.QtCore import Qt
from random import randint
class UI_demo(QWidget):
"""用户界面"""
def __init__(self):
super().__init__()
self.title = 'PyQt5 QLCDNumber'
self.left = 600
self.top = 200
self.width = 500
self.height = 500
self.iconName = '../img/home.ico'
self.initWindow()
def initWindow(self):
self.setWindowIcon(QtGui.QIcon(self.iconName))
self.setGeometry(self.left, self.top, self.width, self.height)
self.setWindowTitle(self.title)
self.initUI()
self.show()
def initUI(self):
"""随机生成数字"""
vbox = QVBoxLayout()
self.lcd = QLCDNumber()
self.lcd.setStyleSheet('background-color:green')
vbox.addWidget(self.lcd)
self.button = QPushButton('random number generator')
self.button.setStyleSheet('background-color:yellow')
self.button.clicked.connect(self.LCDHandler)
vbox.addWidget(self.button)
self.setLayout(vbox)
def LCDHandler(self):
"""随机数字"""
random = randint(1, 200)
self.lcd.display(random)
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = UI_demo()
sys.exit(app.exec_())