from tkinter import *
import pygame.mixer
app = Tk()
app.title("Head First Mix")
sound_file = "50459_M_RED_Nephlimizer.wav"
mixer = pygame.mixer
mixer.init()
def track_start():
track.play(loops = -1)
def track_stop():
track.stop()
def shutdown():
track.stop()
app.destroy()
def track_toogle():
if track_playing.get() == 1:
track_start()
else:
track_stop()
def change_volume(v):
track.set_volume(volume.get())
track_playing = IntVar()
track = mixer.Sound(sound_file)
track_button = Checkbutton(app,
variable = track_playing,
command = track_toogle,
text = "50459_M_RED_Nephlimizer.wav")
track_button.pack(side = LEFT)
volume = DoubleVar()
volume.set(track.get_volume())
volume_scale = Scale(app,
variable = volume,
from_ = 0.0,
to = 1.0,
resolution = 0.1,
command = change_volume,
label = "Volume",
orient = HORIZONTAL)
volume_scale.pack(side = RIGHT)
app.protocol("WM_DELETE_WINDOW", shutdown)
app.mainloop()
目前,我读了一本名为 head first python 的书。在读到第 9 章之前,我什么都懂
为什么我需要“v” - def change_volume(v):
顺便说一句,让您停止、启动和调整曲目的音量