0
我有两个文件,一个包含tkinter代码,另一个包含一个函数。我在tkinter窗口中有一个按钮和一个Entry
字段。我试图在单击按钮时执行该功能,但它需要Entry
字段中的文本才能工作。试图从Tkinter的文件导入任何东西,当我得到一个错误:Tkinter - 在另一个文件中使用Entry值,它本身导入到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
为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'
我在想req_url
没有值s
直接是问题,以及可能导入对方的2个文件,但你如何克服这一点?
谢谢
这么简单,我什至没有想到它。谢谢! – StevenH