이 오류에 대해 몇 가지 질문이 있었기 때문에 중복 게시물로 표시 될 것임을 알고 있습니다. 나는 그것들을 겪었지만 그것을 해결하는 방법을 모릅니다. 제발 도와주세요. 다음은 오류 메시지입니다.
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
return self.func(*args)
File "iptrace.py", line 21, in mbt
tkMessageBox.showinfo(tget, tget+" lives in "+jd["city"]+", "+jd["region"]+" "+jd["country"])
TypeError: cannot concatenate 'str' and 'NoneType' objects
다음은 코드입니다.
from Tkinter import *
import tkMessageBox
import json
import urllib
import sys
def wmi():
uip = urllib.urlopen("http://www.networksecuritytoolkit.org/nst/tools/ip.php").read()
tkMessageBox.showinfo("Whats my IP", "Your IP is "+uip)
def mbt():
global ew1
tget = ew1.get().strip()
jd = json.load(urllib.urlopen("http://ipinfo.io/"+tget+"/geo"))
if tget == "":
tkMessageBox.showerror(tget, "Type a IP Please")
else:
tkMessageBox.showinfo(tget, tget+" lives in "+jd["city"]+", "+jd["region"]+" "+jd["country"])
if __name__ == "__main__":
root = Tk()
root.title("-|IP2Location|-")
textFrame = Frame(root)
entryLabel = Label(textFrame)
entryLabel["text"] = "IP :"
entryLabel.pack(side=LEFT)
ew1 = Entry(textFrame)
ew1["width"] = 24
ew1.pack(side=LEFT)
textFrame.pack()
bmi = Button(root, text="Whats my IP", command=wmi)
bmi.pack()
bs = Button(root, text="Submit", command=mbt)
bs.pack()
def enterPress(event):
mbt()
root.bind("<Return>", enterPress)
def enterPress(event):
exit()
sys.exit(0)
root.bind("<Escape>", enterPress)
root.mainloop()
Traceback에 명시된 오류는 다음 위치에 있습니다.
else:
tkMessageBox.showinfo(tget, tget+" lives in \
"+jd["city"]+", "+jd["region"]+" "+jd["country"])
그래서 문제를 일으키는 것은 당신이 +
두 가지 다른 유형에 대해 기호를 사용하고 있다는 것입니다 . 하나는 a string
이고 다른 하나는 NoneType
가치가 없습니다.
따라서해야 할 일은 str(var)
해당 문 내에서 연결하려는 것을 사용하여 미리 정의 된 변수를 문자열로 변경 하는 것입니다. 그래야만 문제없이 실행됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다