简体   繁体   中英

How do I change/set this Local variable into a global one

def SelectedCarFunction(event=None):
    a = Var2.get()
    b = Var3.get()
    c = Var4.get()  
    if Model == "a" and Colour == "b" and Wheels == "c":
        VarSC = (Three_Series[0])
        print(VarSC)

When I print VarSC from the function it gives me the value I want

VarSC = StringVar()

print(VarSC)

But when I print it outside the function, within my code, it prints "PY_VAR9"

You should return the value of VarSC from the function and print it outside.

def SelectedCarFunction(event=None):
    a = Var2.get()
    b = Var3.get()
    c = Var4.get()  
    if Model == "a" and Colour == "b" and Wheels == "c":
        VarSC = (Three_Series[0])
        return VarSC

print(SelectedCarFunction())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM