j4321 / tkcalendar

Calendar widget for Tkinter
https://pypi.python.org/pypi/tkcalendar
GNU General Public License v3.0
97 stars 33 forks source link

calendar.parse_date returns subclass.get() #96

Open AceScottie opened 1 year ago

AceScottie commented 1 year ago

If you create a subclass of DateEntry then calendar.parse_date uses subclass.get() rather than super().get().

example: (remove the # in the get(self) function to see the error in parse_date) Error occurs when configuring the DateEntry in any way.

import tkinter as tk
from tkcalendar import DateEntry

class overDateEntry(DateEntry):
    def __init__(self, master, **kwargs):
        super(overDateEntry, self).__init__(master)
        self.strvar = tk.StringVar()
        kwargs['textvariable'] = self.strvar
        self.configure(**kwargs)
    def get(self):
        return self.strvar.get()#, True

    def getty(self):
        return self.strvar.get(), True

root = tk.Tk()
de = overDateEntry(root)
de.pack(side=tk.TOP)
root.mainloop()
AceScottie commented 1 year ago

A possible fix for this is to change self.get(), self.insert() and self.delete() functions into super() in all occurrences.

    def _set_text(self, txt):
        """Insert text in the entry."""
        if 'readonly' in self.state():
            readonly = True
            self.state(('!readonly',))
        else:
            readonly = False
        super().delete(0, 'end') ##changed to super()
        super().insert(0, txt) ##changed to super()
        if readonly:
            self.state(('readonly',))

#also change self.get() to super.get() on lines 283, 331 and 432