安裝 pygame 的最佳方法是使用 pip 工具(python 使用它來(lái)安裝包)。請(qǐng)注意,在最新版本中,這與 python 一起提供。我們使用 –user 標(biāo)志告訴它安裝到主目錄,而不是全局。
python -m pip install -U pygame --user
要查看它是否有效,請(qǐng)運(yùn)行包含的示例之一:
python -m pygame.examples.aliens
如果可行,我們就可以開(kāi)始了!
在pygame窗口上顯示圖像有四個(gè)基本步驟:
在這里,我們首先導(dǎo)入所需的庫(kù),然后設(shè)置圖像的寬度和高度,然后創(chuàng)建該尺寸的顯示表面,然后在 image.load() 函數(shù)中給出所需圖像的路徑,最后遍歷列表事件對(duì)象。
# 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()
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
當(dāng)前標(biāo)題:使用PyGame顯示圖像的四種方案-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://chinadenli.net/article16/epidg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、小程序開(kāi)發(fā)、軟件開(kāi)發(fā)、定制開(kāi)發(fā)、網(wǎng)站導(dǎo)航、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容