我在Entry小部件中添加了一些值,并在提交按钮时尝试使用get函数获取该值。但是他们得到了跟随错误,请任何人帮助我。
'UpgradeApp' object has no attribute '_tk'
class UpgradeApp:
def __init__(self):
self.root = tk.Tk()
self.newvalue = tk.StringVar
self.input()
def input(self):
tk.Label(self.root, text="IP Address", relief="groove" ).grid(row=0, columnspan =3, sticky = tk.NSEW)
ip_entry = ttk.Entry(self.root, textvariable = self.newvalue)
ip_entry.grid(column=3, row=0, sticky=tk.W, padx=5, pady=5)
connect = tk.Button(self.root, text="conn", relief="groove", command= self.onclickconnect)
connect.grid(row=1, padx = 5, pady = 5, column = 0)
#connect.bind('<Button-1>',self.onclick)
tk.Button(self.root, text="dlt", relief="groove").grid(row=1, padx = 5, pady = 5, column =1)
tk.Button(self.root, text="clr", relief="groove").grid(row=1, padx = 5, pady = 5, column =2)
def onclickconnect(self):
ip = self.newvalue.get(self)
Node(ip,True, True)
if __name__ == "__main__":
app = UpgradeApp()
app.root.mainloop()
答案 0 :(得分:1)
而不是self.newvalue = tk.StringVar
放self.newvalue = tk.StringVar()
和StringVar.get()
不会接受任何参数,所以它应该是:
def onclickconnect(self):
#ip = self.newvalue.get(self)
ip = self.newvalue.get()
Node(ip,True, True)