你怎么打印一张纸对象查找()到Tkinter文本框中

2024-04-25 17:04:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试将ipwhois查找的结果打印到Tkinter文本框中,但它不起作用。你知道吗

目前我得到这个错误:TclError:wrong#args:should be“.40872632.46072536 insert index chars?标记列表字符标记列表…?“你知道吗

这是我的密码:

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(...)``  

我该如何用换行符打印或至少拆分结果字符串?为什么它不起作用?你知道吗


Tags: text标记obj列表tkinter错误resultspprint
1条回答
网友
1楼 · 发布于 2024-04-25 17:04:23

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

作为旁注,除非self是Tkinter公司()或Tkinter.顶层()或类似的内容,您不应该将其作为文本小部件的父级。除此之外,您还可以将上面的代码剪切并缩短为以下内容:

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

查看this了解更多关于Tkinter的信息-这是一个非常好的Tcl/Tk参考资源。你知道吗

相关问题 更多 >

    热门问题