教你用Python pygame設(shè)置窗口標(biāo)題和圖標(biāo)
pygame.display.set_caption(title, icontitle=None)’’’• title設(shè)置窗口的標(biāo)題內(nèi)容• icontitle設(shè)置圖表化后的小標(biāo)題† 小標(biāo)題可選,部分系統(tǒng)沒(méi)有,一般不設(shè)置’’’
pygame.display.get_caption()’’’• 返回當(dāng)前設(shè)置窗口的標(biāo)題及小標(biāo)題內(nèi)容• 返回結(jié)構(gòu)為(title, icontitle)• 該函數(shù)與游戲交互邏輯配合,可以根據(jù)游戲情節(jié)修改標(biāo)題內(nèi)容’’’設(shè)置圖標(biāo)
pygame.display.set_icon(surface)’’’• 設(shè)置窗口的圖標(biāo)效果• 圖標(biāo)是一個(gè)Surface對(duì)象’’’
游戲帶圖標(biāo)
我把圖標(biāo)改成我的CSDN頭像了格式:(128px*128px png格式)
導(dǎo)入圖片設(shè)置成圖標(biāo)。
import pygame,syspygame.init()icon = pygame.image.load('img/xyicon.png')pygame.display.set_icon(icon) #設(shè)置圖標(biāo)v = pygame.display.Info()size = width,height = 600,400speed = [1,1]BLACK = 0, 0, 0s = pygame.display.set_mode(size,pygame.RESIZABLE)pygame.display.set_caption('hi 滑稽')ball = pygame.image.load('img/361.png')ballrect = ball.get_rect()fps = 200fclock = pygame.time.Clock()while True: for event in pygame.event.get():if event.type == pygame.QUIT: sys.exit()elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT:speed[0] = speed[0] if speed[0] == 0 else (abs(speed[0]) - 1)*int(speed[0]/abs(speed[0])) elif event.key == pygame.K_RIGHT:speed[0] = speed[0] + 1 if speed[0] > 0 else speed[0] - 1 elif event.key == pygame.K_UP:speed[1] = speed[1] + 1 if speed[1] > 0 else speed[1] - 1 elif event.key == pygame.K_DOWN:speed[1] = speed[1] if speed[1] == 0 else (abs(speed[1]) - 1)*int(speed[1]/abs(speed[1])) elif event.key == pygame.K_ESCAPE: # 獲取ESC 按下時(shí)退出sys.exit()elif event.type == pygame.VIDEORESIZE: size = width,height = event.w,event.h s = pygame.display.set_mode(size,pygame.RESIZABLE) ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width:speed[0] = - speed[0] if ballrect.top < 0 or ballrect.bottom > height:speed[1] = - speed[1] pygame.display.get_caption() s.fill(BLACK) s.blit(ball, ballrect) pygame.display.update() fclock.tick(fps)屏幕控制
pygame.display.get_active()’’’• 當(dāng)窗口在系統(tǒng)中顯示(屏幕繪制/非圖標(biāo)化)時(shí)返回True,否則返回Falsepygame.display.get_active()• 該函數(shù)可以用來(lái)判斷是否游戲窗口被最小化• 進(jìn)一步,判斷后可以暫停游戲,改變響應(yīng)模式等’’’
刷新
pygame.display.flip()# • 重新繪制整個(gè)窗口pygame.display.update()#• 僅重新繪制窗口中有變化的區(qū)域,相比.flip()執(zhí)行更快判斷窗體
如果窗體最小化則小球停止運(yùn)動(dòng)。在小球運(yùn)動(dòng)代碼前加上此條件即可
到此這篇關(guān)于教你用Python pygame設(shè)置窗口標(biāo)題和圖標(biāo)的文章就介紹到這了,更多相關(guān)pygame設(shè)置窗口標(biāo)題和圖標(biāo)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. python web框架的總結(jié)2. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式3. Python如何進(jìn)行時(shí)間處理4. python使用ctypes庫(kù)調(diào)用DLL動(dòng)態(tài)鏈接庫(kù)5. 詳解Python模塊化編程與裝飾器6. Python基于pyjnius庫(kù)實(shí)現(xiàn)訪問(wèn)java類7. Python使用shutil模塊實(shí)現(xiàn)文件拷貝8. Python實(shí)現(xiàn)迪杰斯特拉算法過(guò)程解析9. html小技巧之td,div標(biāo)簽里內(nèi)容不換行10. python裝飾器三種裝飾模式的簡(jiǎn)單分析
