人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

教你用Python pygame設(shè)置窗口標(biāo)題和圖標(biāo)

發(fā)布日期:2022-03-11 09:24 | 文章來(lái)源:CSDN

窗口標(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,sys
pygame.init()
icon = pygame.image.load("img/xyicon.png")
pygame.display.set_icon(icon)  #設(shè)置圖標(biāo)
v = pygame.display.Info()
size = width,height = 600,400
speed = [1,1]
BLACK = 0, 0, 0
s = pygame.display.set_mode(size,pygame.RESIZABLE)
pygame.display.set_caption("hi 滑稽")
ball = pygame.image.load("img/361.png")
ballrect = ball.get_rect()
fps = 200
fclock = 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,否則返回False
pygame.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)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

美國(guó)服務(wù)器租用

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開(kāi)通

自選配置、實(shí)時(shí)開(kāi)通

免備案

全球線路精選!

全天候客戶(hù)服務(wù)

7x24全年不間斷在線

專(zhuān)屬顧問(wèn)服務(wù)

1對(duì)1客戶(hù)咨詢(xún)顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部