from Tkinter import *
import tkMessageBox
import pygame.mixer
# create GUI window
app = Tk()
app.title("Head Frist Mix")
sound_file = "50459_M_RED_Nephlimizer.wav"
# start the sounds system
mixer = pygame.mixer
mixer.init()
# create function
def track_toggle():
if track_playing.get() == 1:
track.play(loops = -1)
else:
track.stop()
# create function volume
def change_volume(v):
track.set_volume(volume.get())
track = mixer.Sound(sound_file)
track_playing = IntVar()
# create check button
track_button = Checkbutton(app, variable = track_playing,
command = track_toggle,
text = sound_file)
track_button.pack(side = LEFT)
# create scale button
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)
# GUI loop
app.mainloop()
I the above code I have two questions. At the very top I've imported "from Tkinter import * & import tkMessageBox". Why would I need to import tkMessageBox if I've already imported everything in Tkinter via "from Tkinter import *"?
Secondly, of all GUI controls I've ever added the first parameter was always the name of my Tk object, in this case (app). So why doesn't the Scale control also need "app" as it's fist parameter? Thanks.