求高手指教,关于DoubleVar(),程序已有,但是不知道为什么不合适。
from tkinter import *import pygame.mixer
app=Tk()
app.title("Head First Mix")
sound_file=("D:\\PythonX\\Lib\\site-packages\\pygame\\examples\\data\\boom.wav")
mixer=pygame.mixer
mixer.init()
def track_toggles():
if track_playing.get()==1:
track.play(loops=-1)
else:
track.stop()
def change_volume(v):
track.set_volume(volume.get())
track=mixer.Sound(sound_file)
track_playing=IntVar()
track_button=Checkbutton(app,variable=track_playing,command=track_toggles,text="Play/Stop").pack(side=LEFT)
#volume=DoubleVar()
volume.set(track.get_volume())
volume_scale=Scale(variable=volume,from_=0.0,to=1.0,resolution=0.1,command=change_volume,label="Volume",orient=HORIZONTAL)
volume_scale.pack(side=RIGHT)
def shutdown():
track.stop()
app.destroy()
app.protocol("WM_DELETE_WINDOW",shutdown)
app.mainloop()