網(wǎng)站首頁 編程語言 正文
安裝pygame
安裝 pygame 的最佳方法是使用 pip 工具(python 使用它來安裝包)。請注意,在最新版本中,這與 python 一起提供。我們使用 –user 標(biāo)志告訴它安裝到主目錄,而不是全局。
python -m pip install -U pygame --user
要查看它是否有效,請運(yùn)行包含的示例之一:
python -m pygame.examples.aliens
如果可行,我們就可以開始了!
在pygame窗口上顯示圖像有四個(gè)基本步驟:
- 使用pygame 的display.set_mode()方法創(chuàng)建一個(gè)顯示表面對象。
- 使用 pygame 的 image.load() 方法創(chuàng)建一個(gè) Image 表面對象,即在其上繪制圖像的表面對象。
- 使用pygame顯示表面對象的blit()方法將圖像表面對象復(fù)制到顯示表面對象。
- 使用 pygame 的display.update()方法在 pygame 窗口上顯示顯示表面對象。
使用 PyGame 顯示圖像
在這里,我們首先導(dǎo)入所需的庫,然后設(shè)置圖像的寬度和高度,然后創(chuàng)建該尺寸的顯示表面,然后在 image.load() 函數(shù)中給出所需圖像的路徑,最后遍歷列表事件對象。
# importing required library
import pygame
# activate the pygame library .
pygame.init()
X = 800
Y = 800
# create the display surface object
# of specific dimension..e(X, Y).
scrn = pygame.display.set_mode((X, Y))
# set the pygame window name
pygame.display.set_caption('image')
# create a surface object, image is drawn on it.
imp = pygame.image.load("avatar.jpeg").convert()
# Using blit to copy content from one surface to other
scrn.blit(imp, (0, 0))
# paint screen one time
pygame.display.flip()
status = True
while (status):
# iterate over the list of Event objects
# that was returned by pygame.event.get() method.
for i in pygame.event.get():
# if event object type is QUIT
# then quitting the pygame
# and program both.
if i.type == pygame.QUIT:
status = False
# deactivates the pygame library
pygame.quit()
總結(jié)
原文鏈接:https://blog.csdn.net/qq_39132095/article/details/128046484
相關(guān)推薦
- 2022-12-28 jquery實(shí)現(xiàn)點(diǎn)擊瀏覽器返回上一頁按鈕并能直接刷新_jquery
- 2022-11-02 Golang實(shí)現(xiàn)多存儲(chǔ)驅(qū)動(dòng)設(shè)計(jì)SDK案例_Golang
- 2022-04-11 golang如何操作csv文件詳解_Golang
- 2022-03-19 C語言常量介紹_C 語言
- 2023-05-30 基于CUDA?out?of?memory的一種神奇解決方式_python
- 2022-10-12 Xshell7遠(yuǎn)程連接失敗(connection?failed)的問題解決_Linux
- 2022-03-30 .Net?Core以windows服務(wù)方式部署_C#教程
- 2022-01-17 Failed to load resource: the server responded with
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支