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

# create function
def track_toggle():
    if track_playing.get() ==  1: = -1)

# create function volume
def change_volume(v):

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_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():

app.protocol("WM_DELETE_WINDOW", shutdown)

# GUI loop

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.

1) Because they are different modules:

>>> import Tkinter
>>> Tkinter
<module 'Tkinter' from 'D:\Python27\lib\lib-tk\Tkinter.pyc'>
>>> import tkMessageBox
>>> tkMessageBox
<module 'tkMessageBox' from 'D:\Python27\lib\lib-tk\tkMessageBox.pyc'>

Second question I don't know to answer.

Tkinter is remarkably tolerant, you can use or leave off app in the Scale or Checkbutton widgets. Since there is only one parent, Tkinter figures it out. It is a good habit to put the parent in, just in case there is more than one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.