June 21st, 2005, 09:18 PM
alright im having a little trouble with tkinter events... i have the event set up so when you hit enter it starts a function. here is my code.
now it gives me this error when i hit enter.
from Tkinter import *
def __init__(self, root):
self.root = root
print "You hit enter"
root = Tk()
app = App(root)
i've tried adding "()" after self.place but then when i ran the program it ran self.place right away and nothing happened when i clicked enter.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\PYTHON2.4\lib\lib-tk\Tkinter.py", line 1345, in __call__
TypeError: place() takes exactly 1 argument (2 given)
June 22nd, 2005, 12:58 AM
When you hit enter, an event is passed to your function as a second argument. So you have to write
def place(self, event):
June 22nd, 2005, 02:29 PM
alright that works but now i have another problem... i also have a button that goes to self.place when you click it. when i click the button it gives an argument error. do i have to create 2 seperate functions, one for the button and one for the event?
June 22nd, 2005, 02:46 PM
No, just write
so it works with one and two arguments
def place(self, event=None)