当前位置:网站首页>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
边栏推荐
- Jinte Net Foundation will participate in the global strategy conference of dimension chain through online live broadcast
- 基于udp端口猜测的内网穿透
- AXI协议基础知识
- GemBox. Bundle 43.0 Crack
- Solve the problem that jupyter cannot connect to the kernel based on pycharm and Anaconda -- solution 1
- Database backup (MySQL)
- ^32 execution context stack interview questions
- 如何把树结构存储到数据库
- Leetcode 450. 删除二叉搜索树中的节点
- 2022年R1快開門式壓力容器操作考試題庫及模擬考試
猜你喜欢

数据库全量SQL分析与审计系统性能优化之旅

2022g1 industrial boiler stoker test questions and simulation test

2022 simulated examination question bank and simulated examination for crane driver (limited to bridge crane)

tornado环境搭建及基本框架搭建——熟悉的hello world

WYSIWYG markdown editor: typora

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

^32执行上下文栈面试题

Tornado environment construction and basic framework construction -- familiar Hello World

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

Center detection of circular marking points for opencv camera calibration
随机推荐
网络流媒体协议的联系与区别(RTP RTCP RTSP RTMP HLS)
啟牛商學院給的證券賬戶是安全的嗎?開戶收費嗎
Is the securities account given by qiniu business school safe? Do you charge for opening an account
基于udp端口猜测的内网穿透
2022 high altitude installation, maintenance and demolition test simulation 100 questions and online simulation test
[pytest learning] after the pytest case fails to execute, the others will not be executed
【clickhouse专栏】新建库、用户及角色
基于文本驱动用于创建和编辑图像(附源代码)
虚拟局域网划分与虚拟局域网间路由(VLAN)
Char array parsing
Science popularization genius on the left, madman on the right
Oracle生成不重复字符串 sys_guid()与Mysql生成唯一值
从0到1了解Prometheus
Learn about Prometheus from 0 to 1
How to store tree structure in database
Center detection of circular marking points for opencv camera calibration
2022g1 industrial boiler stoker test questions and simulation test
Classic reading of multi task learning: MMOE model
2022年安全员-B证国家题库及模拟考试
Regression prediction | realization of RBF RBF neural network with multiple inputs and single output by MATLAB