Global variable problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Appu2008
    New Member
    • Dec 2007
    • 18

    Global variable problem

    Hi,
    I have 2 functions,in 1 function iam creating an entry box.
    In the other function, how can i access its value. This is like:

    def fun1:
    #Create entry box

    def fun2:
    val=ent.get() #This poses error
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    You can return the box and pass it in as a parameter, or you can declare the variable in global scope and use global variablename in the function to access it.

    [CODE=python]
    #Method 1
    def create():
    tb = textBox()
    tb.setStuff()
    return tb

    def fun2(textbox):
    textbox.doStuff ()

    textbox = create()
    fun2(textbox)

    #Method 2
    textbox = None
    def create():
    global textbox
    textbox = textBox()
    textbox.setStuf fUp()

    def func2():
    global textbox
    textbox.doStuff ()
    [/CODE]

    Comment

    Working...