国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Python趣味挑戰之教你用pygame畫進度條

瀏覽:64日期:2022-06-17 18:57:21
目錄一、初始化主界面二、第一種進度條三、第二種進度條四、第三種進度條五、第四種進度條六、綜合案例一、初始化主界面

import pygamepygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進度條顯示V1.0')clock = pygame.time.Clock()while True: for event in pygame.event.get():if event.type == pygame.QUIT or event.type == pygame.K_F1: pygame.quit() sys.exit() screen.fill((255,255,255)) clock.tick(30) pygame.display.flip()

Python趣味挑戰之教你用pygame畫進度條

二、第一種進度條

(一)核心代碼

pygame.draw.rect(screen,(192,192,192),(5,100,490,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step,20))

(二)設置步長,并循環遞增

step += 1

(三)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進度條顯示V1.0')clock = pygame.time.Clock()step = 0while True: for event in pygame.event.get():if event.type == pygame.QUIT or event.type == pygame.K_F1: pygame.quit() sys.exit() screen.fill((255,255,255)) # screen.fill((0,0,0)) pygame.draw.rect(screen,(192,192,192),(5,100,490,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step % 490,20)) step += 1 clock.tick(60) pygame.display.flip()

(四)運行效果

Python趣味挑戰之教你用pygame畫進度條

三、第二種進度條

(一)核心代碼

pygame.draw.rect(screen,(192,192,192),(5,100,490,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step % 490,20)) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % 490)/490*100)), True, (255,0,0)) screen.blit(text1, (245, 100))

(二)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進度條顯示V1.0')clock = pygame.time.Clock()step = 0while True: for event in pygame.event.get():if event.type == pygame.QUIT or event.type == pygame.K_F1: pygame.quit() sys.exit() screen.fill((255,255,255)) # screen.fill((0,0,0)) pygame.draw.rect(screen,(192,192,192),(5,100,490,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step % 490,20)) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % 490)/490*100)), True, (255,0,0)) screen.blit(text1, (245, 100)) step += 1 clock.tick(60) pygame.display.flip()

(三)運行結果

Python趣味挑戰之教你用pygame畫進度條

四、第三種進度條

(一)核心代碼

pygame.draw.rect(screen,(192,192,192),(5,100,length+10,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step % length,20)) pygame.draw.circle(screen,(0,0,255),(step % length,110),10) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % length)/length*100)), True, (255,0,0)) screen.blit(text1, (245, 100))

(二)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進度條顯示V1.0')clock = pygame.time.Clock()step = 0length = 480while True: for event in pygame.event.get():if event.type == pygame.QUIT or event.type == pygame.K_F1: pygame.quit() sys.exit() screen.fill((255,255,255)) # screen.fill((0,0,0)) pygame.draw.rect(screen,(192,192,192),(5,100,length+10,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step % length,20)) pygame.draw.circle(screen,(0,0,255),(step % length,110),10) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % length)/length*100)), True, (255,0,0)) screen.blit(text1, (245, 100)) step += 1 clock.tick(60) pygame.display.flip()

(三)運行效果

Python趣味挑戰之教你用pygame畫進度條

五、第四種進度條

(一)加載圖片資源

picture = pygame.transform.scale(pygame.image.load(’score/5.png’), (20, 20))

(二)畫進度條

pygame.draw.rect(screen,(192,192,192),(5,100,length+10,20)) pygame.draw.rect(screen,(251,174,63),(5,100,step % length,20))

(三)畫圖片資源

screen.blit(picture,(step%length,100))

(四)畫文字

font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % length)/length*100)), True, (255,0,0)) screen.blit(text1, (245, 100))

(五)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進度條顯示V1.0')clock = pygame.time.Clock()picture = pygame.transform.scale(pygame.image.load(’score/5.png’), (20, 20))step = 0length = 480while True: for event in pygame.event.get():if event.type == pygame.QUIT or event.type == pygame.K_F1: pygame.quit() sys.exit() screen.fill((255,255,255)) # screen.fill((0,0,0)) pygame.draw.rect(screen,(192,192,192),(5,100,length+10,20)) pygame.draw.rect(screen,(251,174,63),(5,100,step % length,20)) screen.blit(picture,(step%length,100)) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % length)/length*100)), True, (255,0,0)) screen.blit(text1, (245, 100)) step += 1 clock.tick(60) pygame.display.flip()

(六)運行效果

Python趣味挑戰之教你用pygame畫進度條

六、綜合案例

(一)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進度條顯示V1.0')clock = pygame.time.Clock()picture = pygame.transform.scale(pygame.image.load(’score/5.png’), (20, 20))step = 0length = 480while True: for event in pygame.event.get():if event.type == pygame.QUIT or event.type == pygame.K_F1: pygame.quit() sys.exit() screen.fill((255,255,255)) # screen.fill((0,0,0)) # 第一種 pygame.draw.rect(screen,(192,192,192),(5,100,490,20)) pygame.draw.rect(screen,(0,0,255),(5,100,step % 490,20)) # 第二種 pygame.draw.rect(screen,(192,192,192),(5,150,490,20)) pygame.draw.rect(screen,(0,0,255),(5,150,step % 490,20)) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % 490)/490*100)), True, (255,0,0)) screen.blit(text1, (245, 150)) # 第三種 pygame.draw.rect(screen,(192,192,192),(5,200,length+10,20)) pygame.draw.rect(screen,(0,0,255),(5,200,step % length,20)) pygame.draw.circle(screen,(0,0,255),(step % length,210),10) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % length)/length*100)), True, (255,0,0)) screen.blit(text1, (245, 200)) # 第四種 pygame.draw.rect(screen,(192,192,192),(5,250,length+10,20)) pygame.draw.rect(screen,(251,174,63),(5,250,step % length,20)) screen.blit(picture,(step%length,250)) font1 = pygame.font.Font(r’C:WindowsFontssimsun.ttc’, 16) text1 = font1.render(’%s %%’ % str(int((step % length)/length*100)), True, (255,0,0)) screen.blit(text1, (245, 250)) step += 1 clock.tick(60) pygame.display.flip()

(二)運行效果

Python趣味挑戰之教你用pygame畫進度條

OK,寫完,本博文純屬科普貼,技術含量不高,入門級別,大家喜歡就好。而且里面代碼相對比較簡單,也沒有考慮優化,大家在實操過程中可以優化完善,并反饋給我一起進步。

到此這篇關于Python趣味挑戰之教你用pygame畫進度條的文章就介紹到這了,更多相關pygame畫進度條內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 久久一区二区三区免费播放 | 日本特级黄毛片毛片视频 | 亚洲在线成人 | 欧美一级片手机在线观看 | 国产老鸭窝毛片一区二区 | 三级网站在线 | 国产妇乱子伦视频免费 | 午夜影院啪啪 | 亚洲天堂2018av | 国产网站黄 | 欧美一级特黄特黄做受 | 欧美另类 videos黑人极品 | 久久亚洲精品中文字幕第一区 | 性感毛片 | 国产成人综合亚洲 | h网站国产| 性夜黄a爽爽免费视频国产 性夜影院爽黄a爽免费看网站 | 国产91精品一区 | 亚洲福利国产精品17p | 国产成人精品免费视 | 久久精品免费观看国产软件 | 男女午夜 | 黄在线网站 | 在线视频精品视频 | 国产精品1页 | 国产精品一区二区三区高清在线 | 日韩区在线 | 在线一区免费视频播放 | 成人在线亚洲 | 亚洲天码中文字幕第一页 | 亚洲欧美高清视频 | 一级免费a | 国产精品videossex另类 | 国产韩国精品一区二区三区久久 | 亚洲国产成人精品91久久久 | 免费黄网在线观看 | 日韩欧美不卡在线 | 青青热在线精品视频免费 | 天堂8中文在线最新版在线 天堂8资源8在线 | 美一级片 | 国产精品国产三级国产an不卡 |