-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatepicker.py
More file actions
61 lines (46 loc) · 1.42 KB
/
datepicker.py
File metadata and controls
61 lines (46 loc) · 1.42 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar, DateEntry
from datetime import date
def pick_calendar():
def save_sel():
global ret
global root
ret = str(cal.selection_get())
root.destroy()
top = tk.Toplevel(root)
today = str(date.today())
year = int(today[0 : 4])
month = int(today[5 : 7])
day = int(today[8: 10])
cal = Calendar(top,
font="Arial 14", selectmode='day',
year=year, month=month, day=day)
cal.pack(fill="both", expand=True)
ttk.Button(top, text="OK", command=save_sel).pack()
def pick_today():
global ret
global root
ret = str(date.today())
root.destroy()
def main():
global root
global ret
root = tk.Tk()
root.title("Pick A Date")
center(root)
s = ttk.Style(root)
s.theme_use('clam')
ttk.Button(root, text='Today', command=pick_today).pack(padx=10, pady=10)
ttk.Button(root, text='Calendar', command=pick_calendar).pack(padx=10, pady=10)
root.mainloop()
return ret
def center(win):
win.update_idletasks()
width = win.winfo_width()
height = win.winfo_height()
x = (win.winfo_screenwidth() // 2) - (width // 2)
y = (win.winfo_screenheight() // 2) - (height // 2)
win.geometry('{}x{}+{}+{}'.format(120, 110, x, y))
if __name__ == "__main__":
main()