手机安卓版Python编译器IDE彩色音乐播放器代码

import pygame
import tkinter as tk
from tkinter import filedialog

初始化 pygame

pygame.mixer.init()

current_song_index = 0

def play_music():
selected_indices = song_list.curselection()
if selected_indices:
global current_song_index
current_song_index = selected_indices[0]
file_path = song_list.get(current_song_index)
if file_path.endswith(’.mp3’) or file_path.endswith(’.wav’) or file_path.endswith(’.ogg’):
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()

def pause_music():
pygame.mixer.music.pause()

def continue_music():
pygame.mixer.music.unpause()

def stop_music():
pygame.mixer.music.stop()

def next_song():
global current_song_index
if current_song_index < song_list.size() - 1:
current_song_index += 1
else:
current_song_index = 0
file_path = song_list.get(current_song_index)
if file_path.endswith(’.mp3’) or file_path.endswith(’.wav’) or file_path.endswith(’.ogg’):
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()

def previous_song():
global current_song_index
if current_song_index > 0:
current_song_index -= 1
else:
current_song_index = song_list.size() - 1
file_path = song_list.get(current_song_index)
if file_path.endswith(’.mp3’) or file_path.endswith(’.wav’) or file_path.endswith(’.ogg’):
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()

def open_file():
file_paths = filedialog.askopenfilenames(filetypes=[(“MP3 Files”, “.mp3"), (“WAV Files”, ".wav”), (“OGG Files”, “*.ogg”)])
for file_path in file_paths:
song_list.insert(tk.END, file_path)

root = tk.Tk()
root.title(“音乐播放器”)

song_list = tk.Listbox(root,background=‘cyan’, selectmode=tk.MULTIPLE)
song_list.place(x=50, y=300, width=600, height=300) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
song_list.config(selectmode=tk.MULTIPLE)

play_button = tk.Button(root,background=‘green’, text=“播放”)
play_button.place(x=100, y=800, width=150, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
play_button.config(command=play_music)

pause_button = tk.Button(root,background=‘yellow’,text=“暂停”, command=pause_music)
pause_button.place(x=300, y=800, width=150, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
pause_button.config(command=pause_music)

continue_button = tk.Button(root,background=‘blue’, text=“继续”, command=continue_music)
continue_button.place(x=300, y=900, width=150, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
continue_button.config(command=continue_music)

stop_button = tk.Button(root,background=‘red’, text=“停止”, command=stop_music)
stop_button.place(x=100, y=900, width=150, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
stop_button.config(command=stop_music)

previous_button = tk.Button(root,background=‘orange’, text=“上一首”, command=previous_song)
previous_button.place(x=500, y=800, width=150, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
previous_button.config(command=previous_song)

next_button = tk.Button(root,background=‘orange’, text=“下一首”, command=next_song)
next_button.place(x=500, y=900, width=150, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
next_button.config(command=next_song)

open_button = tk.Button(root,background=‘purple’, text=“打开文件”, command=open_file)
open_button.place(x=250, y=650, width=200, height=100) # 设置播放按钮的位置为 x=100, y=200,宽度为 80,高度为 30
open_button.config(command=open_file)

root.mainloop()

彩色音乐播放器

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EYYLTV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值