【发布时间】:2021-08-12 00:38:38
【问题描述】:
我已经简化了我在代码中遇到的问题。
我在函数中有几个函数,我发现很难从绑定触发的函数中捕获返回值。
from tkinter import *
root = Tk()
root.title("Test example")
root.geometry("500x500")
def funcl(event):
print("funcl")
def inner_funcl():
print("inner fucntion")
x = 15
return x
x=inner_funcl()
return x
def ppprinter(x):
print(x)
z=funcl(event)
ppprinter(z)
my_button = Button(root,text="Button")
my_button.pack()
my_button.bind("<Button-1>",funcl)
root.mainloop()
【问题讨论】:
-
您无法返回值。您必须使用全局变量或使用 OOP
-
在其他函数中定义函数被认为是不好的做法。还有你想对返回的值做什么?