我用tkinter制作GUI,允许我点击一个按钮来运行端口扫描。我有一个端口扫描脚本可以正常工作,我已经设法通过GUI上的按钮打开端口扫描器,但是当我单独运行端口扫描器时,我收到了一个我没有收到的错误。Gui用按钮打开端口扫描器
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Steve\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "<string>", line 51, in Scan
NameError: name 'IP_Input' is not defined
我的代码:
class CallWrapper:
"""Internal class. Stores function to call when some user
defined Tcl function is called e.g. after an event occurred."""
def __init__(self, func, subst, widget):
"""Store FUNC, SUBST and WIDGET as members."""
self.func = func
self.subst = subst
self.widget = widget
def __call__(self, *args):
"""Apply first function SUBST to arguments, than FUNC."""
try:
if self.subst:
args = self.subst(*args)
return self.func(*args) # THIS IS THE ERROR #
except SystemExit:
raise
except:
self.widget._report_exception()
class XView:
"""Mix-in class for querying and changing the horizontal position
of a widget's window."""
def xview(self, *args):
"""Query and change the horizontal position of the view."""
res = self.tk.call(self._w, 'xview', *args)
这是代码以下为第51行错误
def Scan():
print ('Scan Called.') #Debugging
IP = str(IP_Input.get(0.0, tkinter.END)) #THIS IS ERROR LINE 51#
print ("IP #Debugging")
Start = int(PortS.get(0.0, tkinter.END))
End = int(PortE.get(0.0, tkinter.END))
TestSocket = socket.socket()
CurrentPort = Start
OpenPorts = 0
print ('Starting scan...')
HowFar = int(CurrentPort/End * 100)
ProgText = HowFar, r'%'
Label1.config(text=('Percentage Done:', ProgText))
喜,欢呼声,我希望这会有所帮助: – lee
IP_Input = tkinter.Text(WIN) IP_Input.pack(扩大= tkinter.YES,填写= tkinter.NONE) IP_Input.place_configure(宽度= 120,高度= 20) IP_Input.place_configure(X = 40,Y = 10) 打印( “IP_Input完成”) – lee
这是我的基本GUI - http://pastebin.com/1qgWQ4EL ,这是端口扫描程序 - http://pastebin.com/df2QQr8A,但问题似乎与这_init_.py文件http://pastebin.com/j03AxHPN – lee