python - Accessing inherited method from Toplevel -


toplevel has method distroy i'm having difficulty accessing inside class.

this code works:

top = toplevel() message(top, text="bla bla bla...").pack() button(top, text="dismiss", command=top.distroy).pack() top.mainloop()  

this not:

from tkinter import toplevel,message,button,mainloop  class demo(toplevel):     def __init__(self,title,message,master=none):         toplevel.__init__(self,master)         self.title = title         msg = message(self,text=message)         msg.pack()         button = button(self, text="dismiss", command=self.distroy)         button.pack()  if __name__ == '__main__':     t1 = demo("first toplevel", "some random message text... goes on , on , on...")     t2 = demo("no, don't know!", "i have no idea root window came from...")      mainloop() 

error message:

traceback (most recent call last):   file "c:\users\tyler.weaver\projects\python scripts\two_toplevel.pyw", line 16, in <module>     t1 = demo("first toplevel", "some random message text... goes on , on , on...")   file "c:\users\tyler.weaver\projects\python scripts\two_toplevel.pyw", line 12, in __init__     button = button(self, text="dismiss", command=self.distroy) attributeerror: demo instance has no attribute 'distroy' 

that's because spelling "destroy" wrong:

from tkinter import toplevel,message,button,mainloop  class demo(toplevel):     def __init__(self,title,message,master=none):         toplevel.__init__(self,master)         self.title = title         msg = message(self,text=message)         msg.pack()         # use "self.destroy", not "self.distroy"         button = button(self, text="dismiss", command=self.destroy)         button.pack()  if __name__ == '__main__':     t1 = demo("first toplevel", "some random message text... goes on , on , on...")     t2 = demo("no, don't know!", "i have no idea root window came from...")      mainloop() 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -