TKinter更新scrolledText

时间:2015-11-29 17:40:01

标签: python tkinter

在创建窗口tkinter上。 scrolledText查找要插入但不更新布局的SearchIP()。当我有不同的输入时,SearchIP METHOD永远不会出现。只显示初始值(注意:如果SearchIP返回正确的内容,我会添加一些print语句,例如,当www.google.com返回216.58.192.4(在ide中的控制台中)时,我会添加一些print语句,但此值永远不会显示在ScrolledText中 image of output

from Tkinter import *
 import socket
 try:
# for Python2
import Tkinter as tk
import ScrolledText as tkst
except ImportError:
# for Python3
import tkinter as tk
import tkinter.scrolledtext as tkst

global Filename

root=tk.Tk()

frame = tk.Frame(root,width=100)
label=Label(root,text="http://")
label.grid(row=0,column=0)
entryVar =tk.StringVar()
entry=Entry(root,width=50,textvariable=entryVar)
entry.grid(row='0',column='1',columnspan=8)
def  SearchIP():
  print(entryVar.get())
  add = str(entryVar.get())
  ip_a= socket.gethostbyname(add)
  print(str(ip_a))
  return str(ip_a);

button1 = Button(root,text="Search IP",command=SearchIP)
button1.grid(row=1,column=0)
button2=Button(root,text ="DNS Recon")
button2.grid(row=1,column=1)
button3=Button(root,text ="Port Scanner")
button3.grid(row=1,column=2)
button4=Button(root,text ="Web Crawl")
button4.grid(row=1,column=3)
button5=Button(root,text ="Email Gathering")
button5.grid(row=1,column=4)
frame.grid(row=2,column=0,columnspan=30,rowspan=30)
edit_space = tkst.ScrolledText(
master = frame,
wrap   = 'word',  # wrap text at full words only
width  = 45,      # characters
height = 10,      # text lines
     # background color of edit area
 )
# the padx/pady space will form a frame
edit_space.pack(fill='both', expand=True, padx=8, pady=8)
root.title("E-Z Security Audting")
root.resizable(True,True)
edit_space.insert('insert', SearchIP())


root.mainloop()

还试图修改SearchIP方法并删除return语句 但我得到了这个错误 我删除了return语句但是我收到了这个错误

File"C:/Users/kero/Desktop/Robert_HodgesKeroles_Hakeem_secproject/secproject/new‌​User_Interface.py", line 50, in <module> edit_space.insert('insert', SearchIP()) File "C:\Python27\lib\lib-tk\Tkinter.py", line 2986, in insert self.tk.call((self._w, 'insert', index, chars) + args)

修改后的SearchIP

def  SearchIP():
    add = str(entryVar.get())
    ip_a= socket.gethostbyname(add)

1 个答案:

答案 0 :(得分:1)

您必须在insert()

中使用SearchIP()
import socket

try:
  # for Python2
  import Tkinter as tk
  import ScrolledText as tkst
except ImportError:
  # for Python3
  import tkinter as tk
  import tkinter.scrolledtext as tkst

# --- functions ---

def SearchIP():
    add = entryVar.get()
    ip_a = socket.gethostbyname(add)
    edit_space.insert('insert', ip_a + "\n")

# --- main ---

root = tk.Tk()

root.title("E-Z Security Audting")
root.resizable(True, True)

frame = tk.Frame(root, width=100)
frame.grid(row=2, column=0, columnspan=30, rowspan=30)

label = tk.Label(root, text="http://")
label.grid(row=0, column=0)

entryVar = tk.StringVar()
entry = tk.Entry(root, width=50, textvariable=entryVar)
entry.grid(row=0, column=1, columnspan=8)

button1 = tk.Button(root, text="Search IP", command=SearchIP)
button1.grid(row=1, column=0)

button2 = tk.Button(root, text="DNS Recon")
button2.grid(row=1, column=1)

button3 = tk.Button(root, text="Port Scanner")
button3.grid(row=1, column=2)

button4 = tk.Button(root, text="Web Crawl")
button4.grid(row=1, column=3)

button5 = tk.Button(root, text="Email Gathering")
button5.grid(row=1, column=4)

edit_space = tkst.ScrolledText(
    master=frame,
    wrap='word',  # wrap text at full words only
    width=45,      # characters
    height=10,      # text lines
     # background color of edit area
)
edit_space.pack(fill='both', expand=True, padx=8, pady=8)

root.mainloop()