0
我想使用tkinter制作浏览文件夹按钮并将路径存储到变量中。到目前为止,我能够打印路径,但我无法将其存储在变量中。你能给些建议么?python tkInter浏览文件夹按钮
下面我附上我使用的代码。
from tkinter import filedialog
from tkinter import *
def browse_button():
filename = filedialog.askdirectory()
print(filename)
return filename
root = Tk()
v = StringVar()
button2 = Button(text="Browse", command=browse_button).grid(row=0, column=3)
mainloop()
非常感谢您!
您已将它存储在一个变量中。它存储在'filename'中。如果你想存储其他功能使用,那么你应该使用一个。类b。全局变量。我将在下面提供一个全局变量的示例。 – scotty3785
太棒了!使用全局变量它工作!谢谢!! –