我正在尝试编写一个在循环中播放背景音频文件的脚本。要播放的音频是在音频文件列表中随机选择的。
我尝试这样做:http://www.nerdparadise.com/tech/python/pygame/basics/part3/
写道:
from tkinter import *
import random
import pygame
_songs = ['audio1.ogg', 'audio2.ogg', 'audio3.ogg']
pygame.mixer.init()
_currently_playing_song = None
SONG_END = pygame.USEREVENT+1
pygame.mixer.music.set_endevent(SONG_END)
next_song = random.choice(_songs)
while next_song == _currently_playing_song:
next_song = random.choice(_songs)
_currently_playing_song = next_song
pygame.mixer.music.load(next_song)
pygame.mixer.music.play()
while True:
for event in pygame.event.get():
if event.type == SONG_END:
pygame.mixer.music.load(next_song)
pygame.mixer.music.play()
tk = Tk()
photo = PhotoImage(file="image.GIF")
image_label=Label(tk, image=photo)
image_label.grid(row=0, column=2)
tk.mainloop()
但是我收到了这个错误:
for event in pygame.event.get():
pygame.error: video system not initialized
有没有办法解决这个问题或使用tkinter而不是pygame视频系统使用pygame?