我有一个代码,这是其中的一部分:
import PySimpleGUI as sg
import pygame
class Music:
def __init__(self, file):
self.sound = file
def play(self):
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(self.sound)
pygame.mixer.music.play()
def volchange(volume):
pygame.mixer.music.set_volume(volume) # The set_volume range is from 0.00 to 1.00 (every 0.01)
def isplaying():
return pygame.mixer.music.get_busy()
layout = [
[sg.Button('Play'),
sg.Slider(key = 'volume', range=(0, 100),
orientation='h', size=(10, 15), default_value= 100)]
]
window = sg.Window('Help me', layout)
while True:
event, values = window.read()
if event == 'Play':
path = "song.mp3"
music = Music(path)
music.play()
if Music.isplaying():
Music.volchange(float(values['volume'] / 100))
我希望在移动滑块时音频的音量实时变化。当我放
if = Music.isplaying():
Music.volchange(values['volume'] / 100)
进入循环while True:
没有任何作用。但正如我注意到的,每次按下“播放”按钮时,这个循环都会继续运行。如何isplaying
在循环中设置检查以使其始终有效?
PS我尽量用英语。