我正在玩 Tkinter,当我只要求一个又一个输入时它就可以工作。像'askopenfilename'。但是获得许多弹出窗口并不是那么舒服。我想只构建一个框架来一次获取所有输入。
到目前为止,我发现的只是带有按钮的框架(来自一些教程),用于询问文件名或目录,但我无法读取用户的选择。
import Tkinter, Tkconstants, tkFileDialog
class TkFileDialogExample(Tkinter.Frame):
def __init__(self, root):
Tkinter.Frame.__init__(self, root)
# define buttons
Tkinter.Button(self, text='askopenfilename', command=self.askopenfilename).pack()
Tkinter.Button(self, text='askdirectory', command=self.askdirectory).pack()
def askopenfilename(self):
return tkFileDialog.askopenfilename()
def askdirectory(self):
return tkFileDialog.askdirectory()
if __name__=='__main__':
root = Tkinter.Tk()
TkFileDialogExample(root).pack()
root.mainloop()
这只是构建了我没问题的框架,但它不停地循环,我无法获得用户选择的内容。我想也许我可以简单地获得按钮的功能(因为它是返回)附带的值?
我是否需要创建一个空列表、数组、dic 来存储函数的值,如下所示:Returning a value after calling a function with a button in Tkinter,我还没有尝试过......
还是有其他方法,只是“从按钮”中读取它?