教你用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. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)2. chat.asp聊天程序的編寫(xiě)方法3. 告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單4. html小技巧之td,div標(biāo)簽里內(nèi)容不換行5. jsp文件下載功能實(shí)現(xiàn)代碼6. XHTML 1.0:標(biāo)記新的開(kāi)端7. CSS3中Transition屬性詳解以及示例分享8. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?9. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享10. CSS Hack大全-教你如何區(qū)分出IE6-IE10、FireFox、Chrome、Opera
