[Tkinter] Retrieving a value from a calendar with a single click - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Retrieving a value from a calendar with a single click (/thread-23913.html) |
Retrieving a value from a calendar with a single click - LagratteCchouette - Jan-22-2020 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()) # 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() RE: Retrieving a value from a calendar with a single click - joe_momma - Jan-23-2020 like this?: # coding:utf-8 from tkinter import * from tkcalendar import Calendar, DateEntry def get_my_date(): date= entry_date.get() print(date) root = Tk() root.geometry("500x500") entry_date_label = Label(root, text="Entry date simple click").pack() entry_date = DateEntry(root,) entry_date.pack() btn_submit= Button(root, text='submit',command= get_my_date) btn_submit.pack() root.mainloop() RE: Retrieving a value from a calendar with a single click - LagratteCchouette - Jan-23-2020 Hello Joe, Thank you very much and it works well. But here the selection field looks like a combobox. Can you help me understand if I'm not overdoing it, how to do it for the 2nd method. How to make so that by a double click in this case I can recover the date selected in the calendar? RE: Retrieving a value from a calendar with a single click - joe_momma - Jan-23-2020 when you created the entry widget you added a function call to result_selected and you get an error. Entries don't call function that's where the bind key name the function used. so first of change your entry like so: entry_date = Entry(root)then when you click on the entry it will call the calendar function calendar1. you can use print instead of return def calendar1(event): def result_select(): print(cal.selection_get())# ...rest of your functiondo a search of tkcalendar they made a document pdf with examples and attributes etc. RE: Retrieving a value from a calendar with a single click - LagratteCchouette - Jan-26-2020 Thank you very much. You are nice. I look, I do the research and if I need I come back to you. Its OK !!!! |