Python 3.x ';升级应用程序&x27;对象没有属性'_tk';
我在Entry小部件中添加了一些值,在提交按钮时,我试图使用get函数获取该值。但是他们有以下错误,请任何人帮我Python 3.x ';升级应用程序&x27;对象没有属性'_tk';,python-3.x,tkinter,tk,Python 3.x,Tkinter,Tk,我在Entry小部件中添加了一些值,在提交按钮时,我试图使用get函数获取该值。但是他们有以下错误,请任何人帮我 “UpgradeApp”对象没有属性“\u tk” class UpgradeApp: def __init__(self): self.root = tk.Tk() self.newvalue = tk.StringVar self.input() def input(self): tk.Label(
“UpgradeApp”对象没有属性“\u 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()
类升级应用程序:
定义初始化(自):
self.root=tk.tk()
self.newvalue=tk.StringVar
self.input()
def输入(自):
tk.Label(self.root,text=“IP Address”,relief=“groove”).grid(行=0,列span=3,粘性=tk.NSEW)
ip_entry=ttk.entry(self.root,textvariable=self.newvalue)
ip_entry.grid(列=3,行=0,粘性=tk.W,padx=5,pady=5)
connect=tk.Button(self.root,text=“conn”,relief=“groove”,command=self.onclickconnect)
connect.grid(行=1,padx=5,pady=5,列=0)
#connect.bind(“”,self.onclick)
按钮(self.root,text=“dlt”,relief=“groove”).grid(行=1,padx=5,pady=5,列=1)
按钮(self.root,text=“clr”,relief=“groove”).grid(行=1,padx=5,pady=5,列=2)
def onclickconnect(自):
ip=self.newvalue.get(self)
节点(ip,真,真)
如果名称=“\uuuuu main\uuuuuuuu”:
app=升级app()
app.root.mainloop()
而不是self.newvalue=tk.StringVar
putself.newvalue=tk.StringVar()
和StringVar.get()
不接受任何参数,因此应该是:
def onclickconnect(self):
#ip = self.newvalue.get(self)
ip = self.newvalue.get()
Node(ip,True, True)