当我将此代码集成到我的项目文件中时,我从get方法中获取了空白值,但是当我在单个单独的暂存文件中运行此函数时,便获得了这些值。它没有显示错误。
button6 = Button(configwin, text="IP ADDRESS", font=('arial', 15, 'bold'), fg="black", relief=RAISED,command=lambda:ipconfig())
button6.grid(row=0, column=0)
def ipconfig():
window = Tk()
window.geometry("500x660")
window.configure(bg="white")
window.title("Ip configuration")
u_ip = StringVar()
u_sub = StringVar()
Ipvalue = StringVar()
lbl1 = Label(window, text="IP Address", bg="white", fg="navy blue", bd=10, font=('arial', 10, 'bold'))
lbl1.grid(row=1, column=0)
lbl2 = Label(window, text="Subnet Mask", bg="white", fg="navy blue", font=('arial', 10, 'bold'))
lbl2.grid(row=2, column=0)
lbl3 = Label(window, text="Interface", bg="white", fg="navy blue", font=('arial', 10, 'bold'))
lbl3.grid(row=3, column=0)
txt1 = Entry(window, fg="navy blue", font=('arial', 10), justify=LEFT, textvariable=Ipvalue)
txt1.grid(row=1, column=1)
txt2 = Entry(window, fg="navy blue", font=('arial', 10), justify=LEFT, textvariable=u_sub)
txt2.grid(row=2, column=1)
txt3 = Entry(window, fg="navy blue", font=('arial', 10), justify=LEFT, textvariable=u_ip)
txt3.grid(row=3, column=1)
button1 = Button(window, text="Submit", font=('arial', 10, 'bold'), fg="navy blue", command=lambda: Telnet1())
button1.grid(row=10, column=1)
def Telnet1():
try:
username = "fenil"
password = "123456"
port = 23
cout = 20
rout = 20
print("o")
print(u_ip)
print(Ipvalue)
print(u_sub)
ip_address = Ipvalue.get()
z = ip_address
us_ip = u_ip.get()
us_sub = u_sub.get()
print(us_ip)
print(z)
print(us_sub)
b = "192.168.0.109"
# c = input("")
d = telnetlib.Telnet(b, port, cout)
print("Ok")
# e=d.read_until("username",rout)
d.write(username.encode("ascii") + b"\n")
# f=d.read_until("password",rout)
print("Ok1")
d.write(password.encode("ascii") + b"\n")
time.sleep(1)
print("Ok2")
d.write(b"terminal length 0\n")
time.sleep(1)
d.write(b"\n")
d.write(b"configure terminal")
d.write(b"\n")
time.sleep(1)
d.write(b"int " + us_ip.encode("ascii") + b"\n")
time.sleep(1)
d.write(b"ip address " + z.encode("ascii") + b" " + us_sub.encode("ascii") + b"\n")
time.sleep(1)
d.write(b"no shut")
d.write(b"\n")
time.sleep(1)
d.write(b"exit")
d.write(b"\n")
time.sleep(1)
d.write(b"sh ip int br")
g = d.read_very_eager()
print(g)
d.close()
except IOError:
print("error")
window.mainloop()