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?

1 Answers1

0

The issue here is that when you are trying to get the pprinted value of results2, it's returning None because pprint just writes the output to sys.stdout. When you then go on to do text.insert(Tkinter.INSERT, None) it throws the error that you keep receiving. This basically means you need to find another way to get the formatted string of your list - I'd recommend "\n".join(results).

As a side note, unless self is a Tkinter.Tk() or Tkinter.Toplevel() or something of the sort, you shouldn't have it as the text widget's parent. On top of that, you can cut and shorten the code you have above to the following:

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

Check this out to read more about Tkinter - it's a really great resource for Tcl/Tk reference.

noahbkim
  • 528
  • 2
  • 13