当前位置:网站首页>Create a simple game interface using pyGame
Create a simple game interface using pyGame
2022-06-13 01:12:00 【flysh05】
Installation is required first Pygame modular , stay Python Add a reference to the code .
1. The reference code is as follows :
import pygame
2. Define initialization window functions :
def init_Window():
pygame.init()
global WND
WND = pygame.display.set_mode((318, 566))
pygame.display.setcaption(" Test window ")
In the initialization window function , Define window size and window title .
3. Create a loop , Constantly update the interface and detect events
while True:
init_Window()
bg = pygame.image.load("images/bg1.png")
for eventin pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
WND.blit(bg,(0,0))
pygame.display.update()
Load background image , Place the background picture object on the window , Location (0,0) Leftmost corner , The picture has actual dimensions , Set window size , Set to the same size as the picture background , Just the size of the window covered with the design . Update the interface continuously in the cycle , When an exit event is encountered , perform pygame Exit and application exit .
Picture size :

Set the window size according to the size of the graph

The operation effect is as follows :

边栏推荐
- Rasa对话机器人之HelpDesk (三)
- [server data recovery] successful cases of data loss recovery during data migration between storage servers
- HashSet underlying source code
- 軟件測試的幾種分類,一看就明了
- Web Application & applet application deployment
- Go simple read database
- Remove duplicates from an ordered array
- Liu Hui and introduction to nine chapter arithmetic and island arithmetic
- [003] embedded learning: creating project templates - using stm32cubemx
- Most elements leetcode
猜你喜欢

Ecological convergence NFT attacks, metaverse ape leads the new paradigm revolution of Web 3.0 meta universe

工作与生活

4K sea bottom and water surface fabrication method and ocean bump displacement texture Download

Liu Hui and introduction to nine chapter arithmetic and island arithmetic

Expression tree - medium order printout

軟件測試的幾種分類,一看就明了

Five classic articles worth reading (2)

sort

ES6解构赋值

Binary tree - right view
随机推荐
Jenkins持续集成操作
Study notes on the introduction paper of face recognition deep facial expression recognition: a survey
The scope builder coroutinescope, runblocking and supervisorscope of kotlin collaboration processes run synchronously. How can other collaboration processes not be suspended when the collaboration pro
Leetcode-13- Roman numeral to integer (simple)
Exercise 5.14 input n strings, arrange them in alphabetical order and output them.
软件测试的几种分类,一看就明了
刘徽与《九章算术》《海岛算经》简介
Mathematical knowledge arrangement: extremum & maximum, stagnation point, Lagrange multiplier
Continue when the condition is not asked, execute the parameter you compare
Three threads print digital demo alternately
pycharm add configutions
Deadlock problem summary
Deep learning model pruning
使用Pygame创建一个简单游戏界面
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators
ArrayList underlying source code
生态聚合NFT来袭,Metaverse Ape引领Web 3.0元宇宙新范式革命
[JS component] calendar
leetcode 142. Circular linked list II
Pytorch's leafnode understanding