Is there any standard way tkinter apps allow the user to choose a date?
Not as far as I could find. For anyone who wants to do this in the future:
I used tkSimpleDialog and ttkcalendar.py (with modifications from this SO post) to make a CalendarDialog. The modified versions of the three files are available on my github.
Below is the code in my CalendarDialog.py:
import Tkinter
import ttkcalendar
import tkSimpleDialog
class CalendarDialog(tkSimpleDialog.Dialog):
"""Dialog box that displays a calendar and returns the selected date"""
def body(self, master):
self.calendar = ttkcalendar.Calendar(master)
self.calendar.pack()
def apply(self):
self.result = self.calendar.selection
# Demo code:
def main():
root = Tkinter.Tk()
root.wm_title("CalendarDialog Demo")
def onclick():
cd = CalendarDialog(root)
print cd.result
button = Tkinter.Button(root, text="Click me to see a calendar!", command=onclick)
button.pack()
root.update()
root.mainloop()
if __name__ == "__main__":
main()