How to get date entry values?

309 Views Asked by At

I have code as follows:

class insert_data(tk.Frame): 
    def __init__(self, parent, controller): 
        tk.Frame.__init__(self, parent)

        # create calender dropdown menu
        cal_input = DateEntry(
            self,
            width = 12,
            borderwidth = 2,
            year = 2020,
            background = 'blue'
        )
        cal_input.grid(row = 1, column = 1, padx = 10, pady = 5, sticky = 'ew')

I am trying to get the value from cal_input (date entry widget) and print it on my terminal. However I don't have any idea how to do it. I keep getting errors. I have tried to call class object however I still cannot get the value from the date entry widget. Can anyone give me advice? Any help will be appreciated.

Note: Here is my full code = https://pastebin.com/cYYtBx7b

1

There are 1 best solutions below

0
On

Create a variable entry = StringVar()

text=entry.get() this will store your entry in text

inside cal_input use textvariable=entry

Modified code is given below

class insert_data(tk.Frame): 
    def __init__(self, parent, controller): 
        tk.Frame.__init__(self, parent)

        entry = StringVar()

        # create calender dropdown menu
        cal_input = DateEntry(
            self,
            width = 12,
            borderwidth = 2,
            year = 2020,
            background = 'blue',
            textvariable=entry
        )
        cal_input.grid(row = 1, column = 1, padx = 10, pady = 5, sticky = 'ew')

        print(entry.get())