如何解决Tkinter条目获取错误“ TypeError:get缺少1个必需的位置参数:'self'”
我正在尝试编写一个代码,该代码从Tkinter GUI中获取一个条目并通过API搜索等等。 但是,当我尝试从“条目”小部件获取信息时,显示此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py",line 1883,in __call__
return self.func(*args)
File "C:/Users/User/PycharmProjects/pythonProject/login.py",line 7,in search
EntryResult = Entry.get()
TypeError: get() missing 1 required positional argument: 'self'
Process finished with exit code 0
这是我的代码:
from tkinter import *
from tkinter.ttk import *
import base64
import requests as r
searchup = Tk()
def search():
EntryResult = Entry.get()
hypixelData = r.get('https://api.hypixel.net/player?key={MyAPIKey}&name='+EntryResult).json()
uuid = hypixelData["player"]["uuid"]
encodedData = r.get('https://sessionserver.mojang.com/session/minecraft/profile/'+uuid).json()
encodedCode = encodedData["properties"]["0"]["value"]
decode = base64.decodestring(encodedCode)
print(decode)
Label(searchup,text= "Search MineFriends").grid(column = 5,row = 0,sticky = W,pady = 2)
Entry(searchup).grid(column = 5,row = 1,pady = 2)
Button(searchup,text= "Search player!",command=search).grid(column = 5,row = 2,pady = 2)
searchup.mainloop()
我不太了解问题,我是Python新手
解决方法
需要在get
的实例上调用Entry
方法。您是在 class Entry
上调用它的。
该解决方案类似于以下代码,其中创建Entry
的实例并将其保存在名为search_box
的变量中。然后调用get
的{{1}}方法来获取输入。
search_box
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。