当前位置:网站首页>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 :

边栏推荐
- Kotlin coroutine suspend function suspend keyword
- Plusieurs catégories de tests logiciels sont claires à première vue
- 软件测试的几种分类,一看就明了
- Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing
- [JS component library] drag sorting component
- [JS] battle chess
- Binary tree - right view
- Et5.0 value type generation
- Key point detection data preparation and model design based on u-net Network -- detection model of four key points of industrial components
- Remove duplicates from an ordered array
猜你喜欢

How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators

Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing

Five classic articles worth reading (2)

Rasa dialogue robot helpdesk (III)

sort

Leetcode find duplicates

Self use notes for problem brushing learning

Most elements leetcode

5G工业网关在煤矿行业的应用优势

Traditional machine learning classification model predicts the rise and fall of stock prices under more than 40 indicators
随机推荐
Wikipedia API User Guide
Status of the thread
Kotlin coroutine suspend function suspend keyword
FLIP动画实现思路
MySQL异常:com.mysql.jdbc.PacketTooBigException: Packet for query is too large(4223215 > 4194304)
How to solve the problem of database?
Five classic articles worth reading (2)
Unity calls alertdialog
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of BBI, MTM, obv, CCI and priceosc indicators
Sequence table - find main element
leetcode 206. Reverse linked list
[JS component] custom paging
Install pycharm process
leetcode. 151. flip the words in the string
Characteristics of transactions - persistence (implementation principle)
MySQL transaction
RSA encryption colloquial explanation
Deep learning model pruning
Wangdao machine test - Chapter 6 - maximum common divisor GCD and minimum common multiple LCM
Matrix fast power