1)我收到myText_Box
的属性错误2)我的目标是通过文本框接受用户输入,然后通过API定义方法定义单词。
3)我即将利用这个post来请求一个字符串 - 我解决属性错误有多冷?在此post之后,我正在寻找calc.myText_Box
calc = tk.Tk()
calc.title("VocabU")
Question_1 = str("Define which word?")
FRONT_PAGE = ['Define me!', Question_1]
def retrieve_input():
input = calc.myText_Box.get("1.0",'end-1c')
define_me = dictionary.get_definition(input)
return define_me
USER_INP = retrieve_input()
#RESPONSE = str(dictionary.get_definition(input))
# set up GUI
row = 1
col = 0
for i in FRONT_PAGE:
button_style = 'raised'
#action =
action = lambda x = retrieve_input(): click_event(x)
tk.Button(calc, text = i, width = 17, height = 3, relief = button_style, command = action).grid(row = row, column = col, sticky = 'nesw')
col += 1
if col > 0: # if col > 4
col = 0
row += 1
display = tk.Entry(calc, width = 40, bg = "white", text = Question_1)
#display.pack
display.grid(row = 2, column = 0, columnspan = 1) # columnspan = 5
答案 0 :(得分:1)
您尚未在https://github.com/phillipsk/dictionary_Merriam-Webster_API的代码中的任何位置定义myText_Box
。
尝试引用它会引发属性错误,尝试访问对象上的任何未定义属性也是如此:
>>> a = object()
>>> a.myText_Box
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'myText_Box'
您需要创建文本小部件并将其分配给Tk()
实例calc
:
calc.myText_Box = Text(...)
答案 1 :(得分:-1)
input
是Python中的保留字,尝试使用不同的字!