python - Close main Tkinter window binding a key -
i not understand why code not work:
import tkinter class application (): def__init__(self): self.master = tkinter.tk() self.master.bind("<enter>", self.quit) self.master.mainloop() def quit (self): self.master.destroy() my_app = application()
i keep receiving error: "quit() takes 1 positional argument 2 given". there way close main tkinter window binding key?
thanks
simply add variable quit method ("i","n",etc.), when bind event method, method must able handle said event parameter.
import tkinter class application (): def __ init __ (self): self.master = tkinter.tk() self.master.bind("<enter>", self.quit) self.master.mainloop() def quit (self,n): self.master.destroy() #notice n variable doesnt other "handling" of event, when #it gets 2 arguments can handle 2 parameters without giving exception #the (old) method had space 1 argument (self), moment "bind" button or event #the method must able handle such information my_app = application()
Comments
Post a Comment