Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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 如何将值传递给另一个文件,该文件本身已导入当前文件?_Python_Tkinter_Python Import - Fatal编程技术网

Python 如何将值传递给另一个文件,该文件本身已导入当前文件?

Python 如何将值传递给另一个文件,该文件本身已导入当前文件?,python,tkinter,python-import,Python,Tkinter,Python Import,我有两个文件,一个包含tkinter代码,另一个包含函数。我在tkinter窗口中有一个按钮和一个条目字段。我试图在单击按钮时执行该功能,但它需要条目字段中的文本才能工作。尝试从tkinter文件导入任何内容时出错: tkinter_file.py: import File window = Tk() def input(): s = entry1.get() return s entry1 = Entry(window) button1 = Button(window, te

我有两个文件,一个包含tkinter代码,另一个包含函数。我在tkinter窗口中有一个按钮和一个
条目
字段。我试图在单击按钮时执行该功能,但它需要
条目
字段中的文本才能工作。尝试从tkinter文件导入任何内容时出错:

tkinter_file.py:

import File
window = Tk()
def input():
    s = entry1.get()
    return s

entry1 = Entry(window)
button1 = Button(window, text='GO', command=File.function)
File.py:

from tkinter import *
import tkinter_file

def function():
    req_url = 'http://someurl.com/{}'.format(tkinter_file.input)
    requests get url etc. etc.
当我将
tkinter_文件
导入
file.py
,甚至只导入函数
input
,我似乎就收到了一个错误:

File "/etc/etc/tkinter_file.py", line 75, in <module>
button1 = Button(window, text='GO', command=File.function)
AttributeError: module 'File' has no attribute 'function'
文件“/etc/etc/tkinter_File.py”,第75行,在 button1=按钮(窗口,text='GO',command=File.function) AttributeError:模块“文件”没有“函数”属性
我认为问题在于
req\u url
没有值
s
,也可能是将这两个文件相互导入,但是如何克服这个问题呢?

如果有两个模块,比如
a.py
b.py
,您不能在
a
中导入模块
b
,然后在
b
中导入模块
a
,因为这会创建一个循环的依赖关系,无法明确解决

解决方案是将该函数正常运行所需的内容作为参数传递给
File.function
,即
entry1
的内容

button1 = Button(window, text='GO', command=lambda: File.function(entry1.get()))

如果您有两个模块,例如
a.py
b.py
,则不能在
a
中导入模块
b
,然后在
b
中导入模块
a
,因为这会创建一个循环的依赖关系,无法明确解决

解决方案是将该函数正常运行所需的内容作为参数传递给
File.function
,即
entry1
的内容

button1 = Button(window, text='GO', command=lambda: File.function(entry1.get()))