我用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