Python2.7, Tkinter: instance has no __call__ method

时间:2016-08-31 17:47:38

标签: tkinter calendar

I've searched high and low and haven't been able to figure out what I'm doing wrong now. I am trying to get the date selected in my calendar to appear in the corresponding entry field. But I get this error message:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\NAME\Continuum\Anaconda2\lib\lib-tk\Tkinter.py", line 1537, in __call__
return self.func(*args)
  File "/Desktop/scripts/Test.py", line 503, in show_Calendar2
    self.initialtext2.set(calendar(format_str='%02d-%s-%s'))
AttributeError: Calendar2 instance has no __call__ method

Here is a link to the script with the Calendars in it. The calendars work and will print the date selected when it's clicked but I can't seem to figure out a way to get the selected date to enter into the entry field next to each calendar button in the main window.

I tried using:

self.initialtext2.set(calendar.get_date(format_str='%02d-%s-%s'))

and a few other variations but I'm at a loss as to how to do this. Any help or guidance is appreciated. Thanks in advance!

1 个答案:

答案 0 :(得分:0)

instance has no __call__ method means you are doing something like this:

class SomeClass():...

# create instance of the class:
something = SomeClass()

# try to call the instance:
result = something()

If SomeClass hasn't defined __call__, you'll get the error you are getting.

The error is almost coming from this statement:

calendar(format_str='%02d-%s-%s')

If you look two lines before that in the code you linked to, you'll see this:

calendar = Calendar2(self, format_str='%02d-%s-%s')

Thus, calendar isn't a function, so you can't call it.