欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2021年05月31日 15:34:08   作者:dhjabc_1  
pygame四種方法教會你畫進度條,其實也不難,文中有非常詳細的代碼示例,對正在學(xué)習(xí)python的小伙伴們很有幫助,需要的朋友可以參考下

一、初始化主界面

import pygame

pygame.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()

在這里插入圖片描述

二、第一種進度條

(一)核心代碼

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

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

step += 1

(三)完整代碼

import pygame,sys

pygame.init()
screen = pygame.display.set_mode((500,300))
pygame.display.set_caption("好看的進度條顯示V1.0")
clock = pygame.time.Clock()

step = 0
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))
    # 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()

(四)運行效果

在這里插入圖片描述

三、第二種進度條

(一)核心代碼

 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:\Windows\Fonts\simsun.ttc', 16)
    text1 = font1.render('%s %%' % str(int((step % 490)/490*100)), True, (255,0,0))
    screen.blit(text1, (245, 100))

(二)完整代碼

import pygame,sys

pygame.init()
screen = pygame.display.set_mode((500,300))
pygame.display.set_caption("好看的進度條顯示V1.0")
clock = pygame.time.Clock()

step = 0
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))
    # 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:\Windows\Fonts\simsun.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()

(三)運行結(jié)果

在這里插入圖片描述

四、第三種進度條

(一)核心代碼

 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:\Windows\Fonts\simsun.ttc', 16)
    text1 = font1.render('%s %%' % str(int((step % length)/length*100)), True, (255,0,0))
    screen.blit(text1, (245, 100))

(二)完整代碼

import pygame,sys

pygame.init()
screen = pygame.display.set_mode((500,300))
pygame.display.set_caption("好看的進度條顯示V1.0")
clock = pygame.time.Clock()

step = 0
length = 480
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))
    # 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:\Windows\Fonts\simsun.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()

(三)運行效果

在這里插入圖片描述

五、第四種進度條

(一)加載圖片資源

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:\Windows\Fonts\simsun.ttc', 16)
    text1 = font1.render('%s %%' % str(int((step % length)/length*100)), True, (255,0,0))
    screen.blit(text1, (245, 100))

(五)完整代碼

import pygame,sys

pygame.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 = 0
length = 480
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))
    # 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:\Windows\Fonts\simsun.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()

(六)運行效果

在這里插入圖片描述

六、綜合案例

(一)完整代碼

import pygame,sys

pygame.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 = 0
length = 480
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))
    # 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:\Windows\Fonts\simsun.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:\Windows\Fonts\simsun.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:\Windows\Fonts\simsun.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()

(二)運行效果

在這里插入圖片描述

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

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

相關(guān)文章

  • python如何在一個py文件中獲取另一個py文件中的值(一個或多個)

    python如何在一個py文件中獲取另一個py文件中的值(一個或多個)

    這篇文章主要介紹了python如何在一個py文件中獲取另一個py文件中的值(一個或多個),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • python中的Json模塊dumps、dump、loads、load函數(shù)用法詳解

    python中的Json模塊dumps、dump、loads、load函數(shù)用法詳解

    這篇文章主要介紹了python中的Json模塊dumps、dump、loads、load函數(shù)用法講解,本文逐一介紹結(jié)合實例代碼給大家講解的非常詳細,需要的朋友可以參考下
    2022-11-11
  • python操作ssh實現(xiàn)服務(wù)器日志下載的方法

    python操作ssh實現(xiàn)服務(wù)器日志下載的方法

    這篇文章主要介紹了python操作ssh實現(xiàn)服務(wù)器日志下載的方法,涉及Python建立ssh連接并下載服務(wù)器日志的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • 使用Django簡單編寫一個XSS平臺的方法步驟

    使用Django簡單編寫一個XSS平臺的方法步驟

    這篇文章主要介紹了使用Django簡單編寫一個XSS平臺的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • python實現(xiàn)二叉查找樹實例代碼

    python實現(xiàn)二叉查找樹實例代碼

    這篇文章主要介紹了python實現(xiàn)二叉查找樹實例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • Tensorflow之Saver的用法詳解

    Tensorflow之Saver的用法詳解

    本篇文章主要介紹了Tensorflow之Saver的用法詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • Python?庫?PySimpleGUI?制作自動化辦公小軟件的方法

    Python?庫?PySimpleGUI?制作自動化辦公小軟件的方法

    Python?在運維和辦公自動化中扮演著重要的角色,PySimpleGUI?是一款很棒的自動化輔助模塊,讓你更輕松的實現(xiàn)日常任務(wù)的自動化,下面通過本文給大家介紹下Python?庫?PySimpleGUI?制作自動化辦公小軟件的過程,一起看看吧
    2021-12-12
  • Python下使用Trackbar實現(xiàn)繪圖板

    Python下使用Trackbar實現(xiàn)繪圖板

    這篇文章主要為大家詳細介紹了Python下使用Trackbar實現(xiàn)繪圖板,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Django中url的反向查詢的方法

    Django中url的反向查詢的方法

    本篇文章主要介紹了Django中url的反向查詢的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 如何利用python檢測圖片是否包含二維碼

    如何利用python檢測圖片是否包含二維碼

    這篇文章主要介紹了如何利用python檢測圖片是否包含二維碼,幫助大家更好的利用python處理圖片,感興趣的朋友可以了解下
    2020-10-10

最新評論