python - Tkinter error, binding an entry object with a function, 2 arguments given, 1 needed -


i'm new tkinter. in order learn tkinter, have followed this tutorial, , tried use new little project. however, have error when pressing enter on entry box have created. here code:

# -*- coding: utf-8 -*- import tkinter  class pocketdex(tkinter.tk):     def __init__(self, parent):         tkinter.tk.__init__(self, parent)         self.parent = parent         self.initialize()      def initialize(self):         self.grid()          self.labelvariable = tkinter.stringvar()         self.labelvariable.set("cuvântul căutat este:")         label = tkinter.label(self, textvariable = self.labelvariable, anchor="w")         label.grid(column = 0, row = 0)          self.entry = tkinter.entry(self)         self.entry.grid(column = 1, row = 0, sticky='ew')         self.entry.bind("<return>", self.enterpressed)      def enterpressed(self):         print "it worked!"   if __name__ == "__main__":     app = pocketdex(none)     app.title('★ pocketdex ★')     app.mainloop() 

the error got following:

exception in tkinter callback traceback (most recent call last):   file "c:\python27\lib\lib-tk\tkinter.py", line 1470, in __call__     return self.func(*args) typeerror: enterpressed() takes 1 argument (2 given) 

i don't understand exaclty why there 2 arguments given, using python 2.7.6 on windows 8.1 pro

the other argument event. normal. event has attributes associated can access. example:

event.keysym >>> 'return' 

the easiest way handle modify callback method accept event argument:

def enterpressed(self, event):     print "it worked!" 

more info: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -