-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendarDialog.py
More file actions
41 lines (28 loc) · 1.05 KB
/
CalendarDialog.py
File metadata and controls
41 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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:
class CalendarFrame(Tkinter.LabelFrame):
def __init__(self, master):
Tkinter.LabelFrame.__init__(self, master, text="CalendarDialog Demo")
def getdate():
cd = CalendarDialog(self)
result = cd.result
self.selected_date.set(result.strftime("%m/%d/%Y"))
self.selected_date = Tkinter.StringVar()
Tkinter.Entry(self, textvariable=self.selected_date).pack(side=Tkinter.LEFT)
Tkinter.Button(self, text="Choose a date", command=getdate).pack(side=Tkinter.LEFT)
def main():
root = Tkinter.Tk()
root.wm_title("CalendarDialog Demo")
CalendarFrame(root).pack()
root.mainloop()
if __name__ == "__main__":
main()