このエラーについていくつか質問があったため、これは重複投稿としてマークされることを知っています。私はそれらを経験しましたが、それを解決する方法がわかりませんでした。私を助けてください。これがエラーメッセージです。
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()
トレースバックに記載されているエラーは、次の場所にあります。
else:
tkMessageBox.showinfo(tget, tget+" lives in \
"+jd["city"]+", "+jd["region"]+" "+jd["country"])
したがって、問題の原因は+
、2つの異なるタイプに記号を使用していることです。1つはastring
で、もう1つはNoneType
(つまり、値がありません)。
したがって、実行する必要があるのは、str(var)
そのステートメント内で連結しようとしているものを使用して、事前定義された変数を文字列に変更することです。そうして初めて、問題なく実行されます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加