|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Soundpasnel.py:
from tkinter import *
import pygame.mixer
class SoundPanel(Frame):
def __int__(self,app,mixer,sound_file):
Frame.__init__(self,app)
self.track=mixer.Sound(sound_file)
self.track_playing=IntVar()
track_button=Checkbutton(self,variable=self.track_playing,
command=self.track_toggle,
text=sound_file)
track_button.pack(side=LEFT)
self.volume=DoubleVar()
self.volume.set(self.track.get_volume())
volume_scale=Scale(self,variable=self.volume,
from_=0.0,
to=10.0,
resolution=0.1,
command=self.change_volume,
label="Volume",
orient=HORIZONTAL)
volume_scale.pack(side=RIGHT)
def track_toggle(self):
if self.track_playing.get()==1:
self.track.play(loops=-1)
else:
self.track.stop()
def change_volume(self,v):
self.track.set_volume(self.volume.get())
hfmix.pyw:
from tkinter import *
import pygame.mixer
#from sound_panel import *
from Soundpasnel import *
app=Tk()
app.title("Head First Mix")
mixer=pygame.mixer
mixer.init()
panel=SoundPanel(app,mixer,"hello.wav")
panel.pack()
panel=SoundPanel(app,mixer,"wrong.wav")
panel.pack()
#create_gui(app,mixer,"hello.wav")
#create_gui(app,mixer,"wrong.wav")
def shutdown():
mixer.stop()
app.destroy()
app.protocol("WM_DELETE_WINDOW",shutdown)
app.mainloop()
运行的时候出错:TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given
|
|