简体   繁体   中英

Stuck trying to use a variable in python 3 Tkinter UI

I'm stuck trying to use the variable I need the name of the path of the folder that was selected to print after the predict flag on the exec path line

def clicked():
    folder_selected = filedialog.askdirectory()
    exec(Path("whatevascript.py --weights weights.h5 predict (folder_selected)").read_text())

Python Anonymous Function (Lambda function)

You will need to use a lambda expression as an argument to the command parameter that calls this clicked function in the button that was clicked, and it would go something like this

Button(root, text="Click me", command=lambda :clicked(VARIABLE))

As you can't pass arguments to a the function pointer you are giving to the command parameter

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