简体   繁体   English

python tkinter通过函数接受用户输入

[英]python tkinter accepting user input through function

1) I receive an Attribute Error for myText_Box 1)我收到myText_Box的属性错误

2) My goal is to accept user input through a text box and then define the word through an API definition method. 2)我的目标是通过文本框接受用户输入,然后通过API定义方法定义单词。

3) I am about to utilize this post to ask for a string -- How cold I resolve the attribute error? 3)我将要利用这篇文章来请求一个字符串-我多冷能解决属性错误? Following this post I was attemtping something along the lines of calc.myText_Box 在这篇文章之后,我正在按照calc.myText_Box的方式进行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

You have not defined myText_Box anywhere in the code at https://github.com/phillipsk/dictionary_Merriam-Webster_API . 您尚未在https://github.com/phillipsk/dictionary_Merriam-Webster_API的代码中的任何位置定义myText_Box

Attempting to reference it will raise an Attribute error, as will an attempt to access any undefined attribute on an object: 尝试引用它会引发一个属性错误,以及尝试访问对象上任何未定义属性的尝试:

>>> a = object()
>>> a.myText_Box
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'myText_Box'

You need to create your Text widget and assign it to your Tk() instance, calc : 您需要创建Text小部件并将其分配给Tk()实例calc

calc.myText_Box = Text(...)

input是Python中的保留字,请尝试使用其他输入!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM