pygame随笔-窗口内图像抖动

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018

@author: myhaspl
"""


import sys, pygame
pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0

screen = pygame.display.set_mode(size)

ball = pygame.image.load("test.gif")
ballrect = ball.get_rect()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    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]

    screen.fill(black)
    screen.blit(ball, ballrect)
    pygame.display.flip()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我知道您的问题是关于Python3和pygame开发的音乐播放器。这是一个简单的音乐播放器,使用Python3和pygame库开发。它可以播放MP3格式的音乐文件,具有基本的播放、暂停、停止、下一曲和上一曲等功能。 以下是代码示例: ```python import pygame import os import time class musicplayer: def __init__(self): pygame.init() pygame.mixer.init() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((320, 240)) def play(self, music): pygame.mixer.music.load(music) pygame.mixer.music.play() def pause(self): pygame.mixer.music.pause() def unpause(self): pygame.mixer.music.unpause() def stop(self): pygame.mixer.music.stop() def next(self, musiclist, index): index += 1 if index >= len(musiclist): index = 0 self.play(musiclist[index]) return index def prev(self, musiclist, index): index -= 1 if index < 0: index = len(musiclist) - 1 self.play(musiclist[index]) return index def main(): musiclist = ["music1.mp3", "music2.mp3", "music3.mp3"] index = 0 mp = musicplayer() mp.play(musiclist[index]) while True: mp.clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: mp.stop() pygame.quit() return if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: if pygame.mixer.music.get_busy(): mp.pause() else: mp.unpause() elif event.key == pygame.K_ESCAPE: mp.stop() pygame.quit() return elif event.key == pygame.K_RIGHT: index = mp.next(musiclist, index) elif event.key == pygame.K_LEFT: index = mp.prev(musiclist, index) if __name__ == "__main__": main() ``` 这个音乐播放器使用了pygame库来实现音乐播放和界面显示。它定义了一个`musicplayer`类来管理音乐播放器的各项功能,包括播放、暂停、停止、下一曲和上一曲等。在主程序中,我们可以设置要播放的音乐列表,然后通过按键来控制音乐播放器的各项功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值