Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TkfileDialog中的其他函数如何使用该变量?_Python_User Interface_Tkinter - Fatal编程技术网

Python TkfileDialog中的其他函数如何使用该变量?

Python TkfileDialog中的其他函数如何使用该变量?,python,user-interface,tkinter,Python,User Interface,Tkinter,我打算编写一个GUI来导入URL数据,然后处理这些数据, 所以我有两个按钮。下面是我的代码 from Tkinter import * root=Tk() root.title('Videos Episodes') root.geometry('500x300') def OpenFile(): # import URLs data from local machine paths=tkFileDialog.askopenfilename()

我打算编写一个GUI来导入URL数据,然后处理这些数据, 所以我有两个按钮。下面是我的代码

from Tkinter import *

    root=Tk()
    root.title('Videos Episodes')
    root.geometry('500x300')

    def OpenFile():  # import URLs data from local machine
        paths=tkFileDialog.askopenfilename()
        return paths

    def read_files(paths): #read data from the directory from OpenFile
        with open(paths) as myfile:
                    return data 
    Button(root,text='Input',command=OpenFile).pack()
    Button(root,text='Process',command=read_files).pack()
    root.mainloop()
我的问题是,单击“流程”按钮时,出现了错误: Tkinter回调回溯中出现异常(最近一次调用为last):


如何修复该错误?

如果要传递参数(未指定参数),请使用:

也许,这就是你想要做的(?):


或者,您想将
OpenFile
(单击另一个按钮)的结果存储在全局变量中,并将其作为
read\u files
的参数传递……?

错误说明发生了什么:您没有将任何参数传递到
read\u files()
方法中。你在命令中再次调用第二个按钮。是的。我想将OpenFile的结果存储在一个全局变量中,并将其作为Read_Files()的参数传递
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1532, in __call__
    return self.func(*args) TypeError: read_files() takes exactly 1 argument (0 given)
Button(root,text='Process',command=lambda: read_files('whatever')).pack()
Button(root,text='Process',command=lambda: read_files(OpenFile())).pack()