Python Forum
[Tkinter] Retrieving a value from a calendar with a single click
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Retrieving a value from a calendar with a single click
#1
Hello,
I want to recover the date selected in the calendar which opens with a single click and as soon as I confirm with the OK button I can insert it in the "entry_date" field.
i don't see how to do it, could you please help me.
thank you very much in advance.

but I have an error message on line 30, however I recover my function "result_selected()"

Quote: entry_date = Entry(root,result_select())
NameError: name 'result_select' is not defined


# coding:utf-8
from tkinter import *

try:
    import tkinter as tk
    from tkinter import ttk
except ImportError:
    import tkinter as tk
    import ttk

from tkcalendar import Calendar, DateEntry


def calendar1(event):
    def result_select():
        return cal.selection_get()


    top = tk.Toplevel(root)
    cal = Calendar(top, font="Arial 9", selectmode='day', locale='en_US',
                   cursor="hand1", year=2020, month=2, day=5)
    cal.pack(fill="both", expand=True)
    ttk.Button(top, text="ok", command=result_select).pack()

# Window
root = Tk()
root.geometry("500x500")

entry_date_label = Label(root, text="Entry date simple click").pack()
entry_date = Entry(root,result_select())
entry_date.pack()

# Active calendar
entry_date.bind('<Button-1>', calendar1)  # simple clic

root.mainloop()
Reply


Messages In This Thread
Retrieving a value from a calendar with a single click - by LagratteCchouette - Jan-22-2020, 06:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to set the calendar widget to current date scratchmyhead 4 7,222 May-11-2020, 08:27 PM
Last Post: scratchmyhead
  Tkinter calendar widget scratchmyhead 4 4,396 May-03-2020, 07:01 PM
Last Post: scratchmyhead

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020