也许这很容易,但我只是不明白......
在下面的代码中,“文件打开”按钮将文件名保存为“名称” - 但如何在Tkinter之外访问此变量? “回调”中的返回语句,但是如果回调在“Button”命令中,我将如何访问?
from Tkinter import *
from tkFileDialog import askopenfilename
def callback():
name= askopenfilename()
print name
Button(text='File Open', command=callback).pack(fill=X)
mainloop()
#HOW DO I ACCESS FILENAME AFTER MAINLOOP?
name = ????
答案 0 :(得分:0)
from Tkinter import *
from tkFileDialog import askopenfilename
value_list = []
def callback():
name = askopenfilename()
value_list.append(name)
print name
Button(text='File Open', command=callback).pack(fill=X)
mainloop()
# value_list[0] is filename