[Tutor] tkinter newbie problem

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Sat, 28 Oct 2000 12:31:48 -0700 (PDT)


On Sat, 28 Oct 2000, wheelege wrote:

>   Hi all.  This is probably so mind-numbingly simple but hey - I'm a
> newbie.

Don't worry about it.


> can anyone see any problems with this?

What's happening is that, within makeCommandMenu(), it doesn't know about
variables declared outside of the function, at least unless you explicitly
say that they were defined outside.  This isolation is intensional ---
it's good practice to explicitly pass the variables you need in the
parameter list.

In any case, there are a few ways of fixing this.  The easiest thing to do
is to tell Python to relax: mBar was declared outside of the function.  We
do this by saying:

    global mBar

in the beginning of your makeCommandMenu function.


The other way to fix it is to change makeCommandMenu() to take mBar as its
parameter.  This is better for larger programs, because then
makeCommandMenu will work with any frame that you construct.

###
CmdBtn = makeCommandMenu(mBar)

def makeCommandMenu(mBar):
   # and then the rest of the stuff that you had before...
###