亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

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

import pygamepygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進(jìn)度條顯示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趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

二、第一種進(jìn)度條

(一)核心代碼

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

(二)設(shè)置步長(zhǎng),并循環(huán)遞增

step += 1

(三)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進(jìn)度條顯示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()

(四)運(yùn)行效果

Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

三、第二種進(jìn)度條

(一)核心代碼

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('好看的進(jìn)度條顯示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()

(三)運(yùn)行結(jié)果

Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

四、第三種進(jìn)度條

(一)核心代碼

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('好看的進(jìn)度條顯示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()

(三)運(yùn)行效果

Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

五、第四種進(jìn)度條

(一)加載圖片資源

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

(二)畫進(jìn)度條

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('好看的進(jìn)度條顯示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()

(六)運(yùn)行效果

Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

六、綜合案例

(一)完整代碼

import pygame,syspygame.init()screen = pygame.display.set_mode((500,300))pygame.display.set_caption('好看的進(jìn)度條顯示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()

(二)運(yùn)行效果

Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條

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

到此這篇關(guān)于Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條的文章就介紹到這了,更多相關(guān)pygame畫進(jìn)度條內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 久香草视频在线观看免费 | 青草国产 | 欧美国产亚洲精品高清不卡 | 最新lutube亚洲看片在线观看 | 欧美日本一区二区三区生 | 一级一级女人真片 | 男女啪啪成人免费网站 | 国产高清看片日韩欧美久久 | 国产日本三级欧美三级妇三级四 | 欧美精品免费在线 | 妞干网欧美 | 亚洲香蕉在线 | 女人被狂躁视频免费网站 | 日韩一区二区三 | 上海麻豆文化传媒网站入口 | 色综合婷婷 | 国产视频播放 | 伊人久久婷婷丁香六月综合基地 | 精品国产区一区二区三区在线观看 | 狠狠色丁婷婷综合久久 | 中文字幕一区视频一线 | 精品国产福利一区二区在线 | 爱呦视频在线播放网址 | 久久综合精品视频 | 国产毛片黄片 | 国产欧美日韩在线观看精品 | 国产成人吃奶一区 | 香蕉网站狼人久久五月亭亭 | 一级片免费视频 | 一级黄录像 | 国产高清精品一级毛片 | 一级特黄aa大片欧美 | 看黄色一级毛片 | 精品一成人岛国片在线观看 | 成年女人毛片免费视频 | 亚洲免费大全 | 成人欧美视频免费看黄黄 | 又爽又叫的毛片欧美 | 美女动作一级毛片 | 国产精品伦理久久久久 | 男女做a一级视频免费观看 男女喷水视频 |