This is a Python function question!

Asked 2 years ago, Updated 2 years ago, 13 views

I'm a student programming using Python.

#File Open Function
def openfile():
    filename = filelog.askopenfilename(~~~/omitted/~~) #filename = path to file
    refilename = filename.replace('/', '\\\\')

#Calculation Button Function
def clickOK():

    bname = refilename.encode('utf-8')
    IEEE = C.CDLL('IEEE')

    tole = C.c_double(Margin.get())
    name = C.c_char_p(bname)
    Omitted~~~~~

The value of the refilename used in the "#FileOpen Function" is: I also want to use it in "#calculation button function".

NameError: name 'refilename' is not defined

The above calculation button function is written bname = refilename.code~~ so the above error occurs. How can I write refilename in the function below?

python

2022-09-21 20:32

1 Answers

If you use the declaration function once as global refilename in the openfile() function, it will be used as a global variable This will be available in clickOK().


2022-09-21 20:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.