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