python中pygame針對游戲窗口的顯示方法實例分析(附源碼)
本文實例講述了python中pygame針對游戲窗口的顯示方法。分享給大家供大家參考,具體如下:
在這篇教程中,我將給出一個demo演示:
當(dāng)我們按下鍵盤的‘f'鍵的時候,演示的窗口會切換到全屏顯示和默認(rèn)顯示兩種顯示模式
并且在后臺我們可以看到相關(guān)的信息輸出:

上面給出了一個簡單的例子,當(dāng)然在pygame的官方文檔中有對顯示策略的更權(quán)威的說明:
http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode
''' pygame.FULLSCREEN create a fullscreen display pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL pygame.HWSURFACE hardware accelerated, only in FULLSCREEN pygame.OPENGL create an opengl renderable display pygame.RESIZABLE display window should be sizeable pygame.NOFRAME display window will have no border or controls '''
代碼部分:
#pygame fullscreen
import os, pygame
from pygame.locals import *
from sys import exit
'''
pygame.display.set_mode():
pygame.FULLSCREEN create a fullscreen display
pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL
pygame.HWSURFACE hardware accelerated, only in FULLSCREEN
pygame.OPENGL create an opengl renderable display
pygame.RESIZABLE display window should be sizeable
pygame.NOFRAME display window will have no border or controls
'''
__author__ = {'name' : 'Hongten',
'mail' : 'hongtenzone@foxmail.com',
'Version' : '1.0'}
BG_IMAGE = 'C://py//bg.png'
SCREEN_DEFAULT_SIZE = (500, 500)
pygame.init()
#create the image path
bg_path = os.path.join('data', BG_IMAGE)
if not os.path.exists(bg_path):
print('The BackGround Image does not exist!')
screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
bg = pygame.image.load(bg_path).convert()
#full screen flag
full_screen = False
while 1:
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == KEYDOWN:
#when press the 'f',then change the screen display model
if event.key == K_f:
full_screen = not full_screen
if full_screen:
print('Open the Fullscreen model!')
else:
print('Open the Default model!')
if full_screen:
#full screen display model
screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, FULLSCREEN, 32)
else:
#default model
screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
screen.blit(bg, (0, 0))
pygame.display.update()
完整實例代碼代碼點擊此處本站下載。
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
Python圖像處理實現(xiàn)兩幅圖像合成一幅圖像的方法【測試可用】
這篇文章主要介紹了Python圖像處理實現(xiàn)兩幅圖像合成一幅圖像的方法,結(jié)合實例形式分析了Python使用Image.blend()接口與Image.composite()接口進(jìn)行圖像合成的相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
python中的classmethod與staticmethod
這篇文章主要介紹了python中的classmethod與staticmethod,2022-01-01
Python中如何將Tqdm與Asyncio結(jié)合使用呢
這篇文章主要和大家詳細(xì)介紹了在Python中如何將Tqdm與Asyncio結(jié)合使用呢,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-05-05
如何用 Python 子進(jìn)程關(guān)閉 Excel 自動化中的彈窗
這篇文章主要介紹了如何用 Python 子進(jìn)程關(guān)閉 Excel 自動化中的彈窗,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-05-05
詳解numpy.ndarray.reshape()函數(shù)的參數(shù)問題
這篇文章主要介紹了詳解numpy.ndarray.reshape()函數(shù)的參數(shù)問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Python獲取基金網(wǎng)站網(wǎng)頁內(nèi)容、使用BeautifulSoup庫分析html操作示例
這篇文章主要介紹了Python獲取基金網(wǎng)站網(wǎng)頁內(nèi)容、使用BeautifulSoup庫分析html操作,結(jié)合實例形式分析了Python基于urllib包的網(wǎng)頁內(nèi)容獲取,以及使用BeautifulSoup分析html相關(guān)操作技巧,需要的朋友可以參考下2019-06-06

