当前位置:网站首页>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
边栏推荐
- 2022 high altitude installation, maintenance and demolition test simulation 100 questions and online simulation test
- 我的CのERROR们
- Database backup (MySQL)
- Le compte de titres de l'école de commerce kainiu est - il sécurisé? Frais d'ouverture de compte
- 2022G1工业锅炉司炉考题及模拟考试
- Why does chip design also need "Craftsmanship"?
- Text driven for creating and editing images (with source code)
- 【opencvsharp】opencvsharp_samples.core示例代码笔记
- 消息队列-推/拉模式学习 & ActiveMQ及JMS学习
- web安全-靶场笔记
猜你喜欢

The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)
![[opencvsharp] spot detection barcode decoding image operation image rotation / flip / Zoom perspective transformation image display control demo notes](/img/a7/5b66ef0360ed41441653a413cd9e53.png)
[opencvsharp] spot detection barcode decoding image operation image rotation / flip / Zoom perspective transformation image display control demo notes

2022年危险化学品经营单位主要负责人考试模拟100题及模拟考试

核密度估计(二维、三维)

开关电源电路图及原理12v分析-详细版

GemBox. Bundle 43.0 Crack

Go quick start of go language (I): the first go program

2022年高处安装、维护、拆除考试模拟100题及在线模拟考试

RSP: An Empirical Study of remote sensing pre training

Analysis report on competition pattern and future development strategy of China's corn industry 2022-2028 Edition
随机推荐
Memory image of various data types in C language
接口的特点&&接口与抽象类的对比
2022年安全员-B证国家题库及模拟考试
微服务连接云端Sentinel 控制台失败及连接成功后出现链路空白问题(已解决)
基于udp端口猜测的内网穿透
Web page design example assignment -- Introduction to Henan cuisine (4 pages) web final assignment design web page_ Dessert and gourmet college students' web design homework finished product
Oracle 分析函数 over 和MySQL 实现类似效果写法
“is-a”,“has-a”,“like-a”
启牛商学院给的证券账户是安全的吗?开户收费吗
ShellBrowser .NET Crack
2022 high altitude installation, maintenance and demolition test simulation 100 questions and online simulation test
GemBox.Bundle 43.0 Crack
SQL injection attack under seed emulator (including SQL environment configuration)
【opencvsharp】opencvsharp_samples.core示例代码笔记
关联关系
Global and China Mobile Network Optimization (MnO) industry development panoramic survey and Investment Strategy Research Report 2022-2028
485 days, 21 experiences of my remote office sharing | community essay solicitation
Weekly recommended short video: rookie CEO talks about the new logistics track in the future
ASP.NET教育OA系统源码 教育行业OA系统源码带文档
用实际案例分析PMP与ACP应该考哪个?哪个更有用?