相关文件
想学Python的小伙伴可以关注小编的公众号【Python日志】
有很多的资源可以白嫖的哈,不定时会更新一下Python的小知识的哈!!
需要源码的小伙伴可以在公众号回复 猜数字小游戏
Python源码、问题解答学习交流群:773162165
代码实现
导入PyQt5的相关模块
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
PyQt5的安装,还是采用pip的安装方式。
pip install PyQt5
将准备好的样式导入到代码块中。
# 主题样式模块引用
from QCandyUi import CandyWindow
文件和随机数相关的模块导入进来。
import sys
import random
界面编写函数 init_ui,初始化UI界面及页面布局代码块。
def init_ui(self):
self.setWindowTitle('猜数字游戏 公众号:[Python 日志]')
self.setWindowIcon(QIcon('数字.ico'))
self.setFixedSize(500, 350)
self.msg = QLabel()
self.msg.setText('猜数字游戏')
self.msg.setStyleSheet(
'font-size:50px;text-align:center;font-weight:bold;font-family:"Microsoft JhengHei";')
self.msg.setAlignment(Qt.AlignCenter)
self.in_num = QLineEdit()
self.in_num.setPlaceholderText('请输入目标数字')
self.in_num.setAlignment