我正在编写一个Python脚本,它使用Exscript登录网络交换机来收集信息。我正在使用Tkinter来呈现图形界面。 我正在尝试创建一个状态为画布的窗口,以便在单击“go”按钮时,状态窗口可见,并且当脚本登录到设备时,状态窗口上的标签会更新(登录到y的设备x) )。 我找到了.update()和.update_idletasks(),它在我输入初始函数(单击go按钮)时起作用,但更新标签在Exscript start()函数中发生了2个函数。在我的画布上做的任何事情导致脚本挂起,我必须强行关闭它。
onhost = 0
hostcount = 0
def go_main():
canvas.itemconfig(statuswindow, state='normal')
canvas.itemconfig(statuslabel_window, state='normal')
canvas.update()
filename = InvEntry.get()
accounts = [Account(unameEntry.get(), pwordEntry.get())]
workbook = xlrd.open_workbook(filename)
sheet = workbook.sheet_by_name("Infrastructure")
global hostcount
hostcount = sheet.nrows
hosts = []
for x in range (1, hostcount):
hosts.append(conproto.get() + "://" + sheet.cell_value(x, 0))
start(accounts, hosts, login_func)
def login_func(job, host, conn):
global onhost
global hostcount
onhost = onhost + 1
newstat = "Gathering MACs on switch %s of %s..." % (onhost, hostcount)
stat.set(newstat)
#canvas.update()
conn.execute('term len 0') #We don't want a pause in the output
conn.execute('sh ver') #Make sure we're a Nexus or Catalyst switch before continuing
r = conn.response
if r != '' and ('nx-os' or 'catalyst') in r.lower():
#Grab the device's hostname:
一旦它到达“stat.set(newstat)”行就会挂起。我究竟做错了什么?对不起,如果我屠杀了所有的程序员术语,我是一名假装成为程序员的网络工程师。谢谢!