当前位置:网站首页>GUI guess number game, directly open play
GUI guess number game, directly open play
2022-06-11 16:54:00 【Python concentration camp】
Before the start , Let's take a direct look at the effect after implementation . Children's shoes that want to realize or need the source code directly enter the field ...

take PyQt5 Relevant modules of can be imported directly .
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *To take care of the new attention to children's shoes , Here is an introduction PyQt5 Installation , Or adopt pip Installation method of .
pip install PyQt5Import the prepared style into the code block .
# Theme style module reference
from QCandyUi import CandyWindowFile and random number related modules are imported .
import sys
import randomInterface programming function init_ui, initialization UI Interface and page layout code block .
def init_ui(self):
self.setWindowTitle(' Guess the number game official account :[Python concentration camp ]')
self.setWindowIcon(QIcon(' Numbers .ico'))
self.setFixedSize(500, 350)
self.msg = QLabel()
self.msg.setText(' Guess the number game ')
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(' Please enter the target number ')
self.in_num.setAlignment(Qt.AlignCenter)
self.in_num_btn = QPushButton()
self.in_num_btn.setText(' Is it the ')
self.in_num_btn.clicked.connect(self.in_num_btn_click)
self.tar_num_btn = QPushButton()
self.tar_num_btn.setText(' Show numbers ')
self.tar_num_btn.clicked.connect(self.tar_num_btn_click)
self.tar_num = QLabel()
self.tar_num.setText('#####')
self.tar_num.setFixedWidth(50)
self.generate_num_btn = QPushButton()
self.generate_num_btn.setText(' Generate target number ')
self.generate_num_btn.clicked.connect(self.generate_num_btn_click)
hbox = QHBoxLayout()
hbox.addWidget(self.tar_num)
hbox.addWidget(self.tar_num_btn)
hbox.addStretch(1)
hbox.addWidget(self.generate_num_btn)
vbox = QVBoxLayout()
vbox.addStretch(1)
vbox.addWidget(self.msg)
vbox.addWidget(self.in_num)
vbox.addWidget(self.in_num_btn)
vbox.addStretch(1)
vbox.addLayout(hbox)
self.setLayout(vbox)Slot function generate_num_btn_click, Used to generate the target number of the number guessing game .
def generate_num_btn_click(self):
tar_num = random.randint(1, 99)
self.num = tar_num
# Reset the maximum and minimum values
self.max_num = 100 # Current maximum
self.min_num = 0 # Current minimum Slot function tar_num_btn_click, Used to show or hide the target number .
def tar_num_btn_click(self):
if self.num != 0 and self.tar_num_btn.text().strip() == ' Show numbers ':
self.tar_num.setText(str(self.num))
self.tar_num_btn.setText(' Hide numbers ')
elif self.tar_num_btn.text().strip() == ' Hide numbers ':
self.tar_num.setText('#####')
self.tar_num_btn.setText(' Show numbers ')Slot function in_num_btn_click, The main code logic used to deal with the implementation of guessing numbers .
def in_num_btn_click(self):
try:
in_num = int(self.in_num.text().strip())
if in_num < self.min_num or in_num >= self.max_num:
pass
else:
if self.num == 0:
self.msg.setText(' No target number ')
elif in_num == self.num:
self.msg.setText(' congratulations , Guessed it ')
else:
if in_num < self.num:
self.msg.setText(str(in_num) + ' - ' + str(self.max_num))
self.min_num = in_num
elif in_num > self.num:
self.msg.setText(str(self.min_num) + ' - ' + str(in_num))
self.max_num = in_num
except:
self.msg.setText(' Please enter a number ')Last , By calling the blue theme style of the theme module, the whole App Become beautiful .
CandyWindow.createWindow(GuessNumber(), theme='blue', title=' Guess the number game official account :[Python concentration camp ]',
ico_path=' Numbers .ico')Reply in official account " Guess the number game ", Get the full source code .
【 Past highlights 】
Teach you how to make a data chart generator ( Source code attached )...
Dynamic pointer clock : utilize pyqt5 Make a pointer clock to display real-time time
python The brightest boy in the log , It's my favorite fancy acridine ...
hashlib.md5() Function to filter out duplicate files in the system and remove them ...
Hassa gave , Here comes the hero League full skin downloader ...
PyQt5 Production of sensitive word detection tool based on , The gospel of the operator ...
Hand drawn picture generator : Shuey Rhon Rhon as an example, one button generation ...
The most beautiful form viewing plug-in :tabulate
Tiktok system in the same class ,PyQt5 It's easy to write ...
Lunar New Year's Eve 、 Made a windows Notification manager !
gif Dynamic picture generator , Multiple pictures are combined to generate a moving picture ...
Baidu Image Downloader 2.0
边栏推荐
- WYSIWYG markdown editor: typora
- A journey of database full SQL analysis and audit system performance optimization
- Text driven for creating and editing images (with source code)
- DFS和BFS笔记(一)基于C语言的广度优先搜索
- JINTE NET基金会将通过线上直播参与维度链全球战略发布会
- Oracle generates non duplicate string sys_ Guid() and MySQL generate unique values
- 数据库备份(Mysql)
- 用实际案例分析PMP与ACP应该考哪个?哪个更有用?
- Leetcode 450. Deleting a node in a binary search tree
- 2022 high voltage electrician special operation certificate examination question bank and online simulation examination
猜你喜欢

二级造价工程师值得考吗?发展前景如何?

A set of ThinkPHP wechat applet mall source code with background management

unittest 如何知道每个测试用例的执行时间

Opencv相机标定之圆形标识点中心检测

Leetcode 1974. Minimum time to type words using a special typewriter (yes, once)

AXI协议基础知识

^31原型面试题

Elasitcsearch basic learning notes (1)

Switching power supply circuit diagram and principle 12V analysis - detailed version

Differences between list and set access elements
随机推荐
[Clickhouse column] create a new library, user and role
Common tools and commands for information collection
GemBox. Bundle 43.0 Crack
cocoapod只更新指定库(不更新索引)
Analysis report on the "fourteenth five year plan" proposal and innovation environment of global and Chinese sodium pyrophosphate industry (2022-2028)
每周推荐短视频:菜鸟CEO谈未来物流新赛道
Oracle database merge row records, wmsys WM_ Use of the concat function and group in MySQL_ Use and comparison of concat (ID).
啟牛商學院給的證券賬戶是安全的嗎?開戶收費嗎
2022熔化焊接与热切割上岗证题目及模拟考试
Redis - learn five types of NoSQL
Pycharm使用小技巧 - 如何设置背景图片
Time series prediction | MATLAB realizes future multi-step prediction of RBF RBF neural network time series
Katalon Studio Enterprise
CLP Jinxin helps Rizhao bank put into operation its new financial ecological network
2022g1 industrial boiler stoker test questions and simulation test
【opencvsharp】opencvsharp_ samples. Core sample code Notes
Why does chip design also need "Craftsmanship"?
ASP. Net education OA system source code education industry OA system source code with document
[ISITDTU 2019]EasyPHP
Cocoapod only updates the specified library (does not update the index)