0

I've been trying to print the results of an ipwhois lookup into a Tkinter textbox but it's not working.

Currently i Get this error: TclError: wrong # args: should be ".40872632.46072536 insert index chars ?tagList chars tagList ...?"

Here's my code:

result2=unicode(set(ipList).intersection(testList));
result3=result2[:19].strip()
result4=result3[6:]
obj = ipwhois.IPWhois(result4)
results = obj.lookup()
results2= pprint.pprint(results)
text = Tkinter.Text(self)
text.insert(Tkinter.INSERT, results2)
text.insert(Tkinter.END, "")
text.pack()
text.grid(...)``  

How do I pprint or at least split the results string by newline and why does it not work?

4

1 回答 1

0

这里的问题是,当您尝试获取 results2 的 pprinted 值时,它会返回,None因为 pprint 只是将输出写入sys.stdout. 当你继续这样做text.insert(Tkinter.INSERT, None)时,它会抛出你不断收到的错误。这基本上意味着您需要找到另一种方法来获取列表的格式化字符串 - 我建议"\n".join(results)

作为旁注,除非self是 Tkinter.Tk() 或 Tkinter.Toplevel() 或类似的东西,否则您不应该将它作为文本小部件的父级。最重要的是,您可以将上面的代码剪切并缩短为以下内容:

results2 = "\n".join(results)
text = Tkinter.Text(self)
text.insert(Tkinter.END, results2) # Write the string "results2" to the text widget
text.pack()
# text.grid(...) # Skip this, you don't need two geometry managers

查看内容以了解有关 Tkinter 的更多信息 - 它是 Tcl/Tk 参考的非常好的资源。

于 2014-04-21T00:14:18.003 回答