Skip to content

Commit 612f2ce

Browse files
committed
Simple DOB selection app using Tkinter
This app demonstrates use of the Spinbox and ConboBox in tkinter
1 parent 64ed15c commit 612f2ce

File tree

2 files changed

+125
-13
lines changed

2 files changed

+125
-13
lines changed

src/main.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
This is the main file and will import other modules/codes written for python
77
'''
88

9-
import program1 as p1
10-
import program2 as p2
11-
import program3 as p3
12-
import program4 as p4
13-
import program5 as p5
14-
import program6 as p6
15-
9+
# import program1 as p1
10+
# import program2 as p2
11+
# import program3 as p3
12+
# import program4 as p4
13+
# import program5 as p5
14+
# import program6 as p6
15+
import program7 as p7
1616
def main():
17-
p1.sayhello()
18-
p2.HelloAppLaunch()
19-
p3.GreetingAppLaunch()
20-
p4.launchButtonApp()
21-
p5.launchButton2App()
22-
p6.launchEntryApp()
17+
# p1.sayhello()
18+
# p2.HelloAppLaunch()
19+
# p3.GreetingAppLaunch()
20+
# p4.launchButtonApp()
21+
# p5.launchButton2App()
22+
# p6.launchEntryApp()
23+
p7.launchSimpleCalenderApp()
2324

2425
if __name__ == '__main__':main()

src/program7.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
'''
2+
Created on Oct 21, 2017
3+
4+
@author: Aditya
5+
This program demonstrates the use of spinbox and combobox in tkinter
6+
'''
7+
8+
import tkinter as tk
9+
from tkinter import ttk
10+
import datetime
11+
import calendar
12+
13+
class simpleCalender:
14+
'''
15+
This class creates a simple date of birth app using tkinter
16+
'''
17+
def __init__(self, master):
18+
ttk.Label(master, text = 'DATE OF BIRTH').pack()
19+
#####################################################################
20+
21+
ttk.Label(master, text = 'Select Year').pack()
22+
self.year = tk.StringVar()
23+
self.spinbxyear = tk.Spinbox(master, from_ = 1900,
24+
to = datetime.datetime.now().year,
25+
textvariable = self.year)
26+
self.spinbxyear.pack()
27+
28+
#####################################################################
29+
30+
ttk.Label(master, text = 'Select Month').pack()
31+
self.month = tk.StringVar()
32+
self.combobox = ttk.Combobox(master, textvariable = self.month) # textvariable - variable tied to value selected in combobox
33+
self.combobox.pack()
34+
35+
# values which combobox can take
36+
self.combobox.config(values = ('January', 'February', 'March', 'April',
37+
'May', 'June', 'July', 'August', 'September',
38+
'October', 'November', 'December'))
39+
self.combobox.set('January')
40+
41+
#####################################################################
42+
43+
ttk.Label(master, text = 'Select Date').pack()
44+
self.dateofmonth = tk.StringVar()
45+
self.lastday = 31
46+
self.spinbxday = tk.Spinbox(master, from_ = 1, to = 31,
47+
textvariable = self.dateofmonth)
48+
self.spinbxday.pack()
49+
50+
#####################################################################
51+
52+
ttk.Button(master, text = "Get Date of Birth", command = self.getDOB).pack()
53+
54+
#####################################################################
55+
# Display Date of Birth
56+
self.displaydob = ttk.Label(master, text = "Please select a date")
57+
self.displaydob.pack()
58+
59+
################ METHODS ####################################################
60+
def getyear(self):
61+
if int(self.year.get()) in range(int(self.spinbxyear['from']), int(self.spinbxyear['to']+1)):
62+
return int(self.year.get())
63+
else:
64+
return -1
65+
66+
def getmonth(self):
67+
if self.month.get() in self.combobox['values']:
68+
return self.month.get()
69+
else:
70+
return -1
71+
72+
def getdate(self):
73+
if int(self.dateofmonth.get()) in range(1, 32):
74+
return int(self.dateofmonth.get())
75+
else:
76+
return -1
77+
78+
def getDOB(self):
79+
year = self.getyear()
80+
month = self.getmonth()
81+
82+
if calendar.isleap(year) and month=='February':
83+
self.lastday = 29
84+
elif not calendar.isleap(year) and month=='February':
85+
self.lastday = 28
86+
elif month in ('January', 'March', 'May', 'July', 'August', 'October', 'December'):
87+
self.lastday = 31
88+
elif month in ('April', 'June', 'September', 'November'):
89+
self.lastday = 30
90+
else:
91+
self.lastday = -1
92+
93+
if self.getdate() > self.lastday or self.getdate()<1 or self.lastday == -1:
94+
date = -1
95+
else:
96+
date = self.getdate()
97+
98+
if year != -1 and month != -1 and date != -1:
99+
self.displaydob.config(text = '{0} {1}, {2}'.format(month, date, year))
100+
else:
101+
self.displaydob.config(text = "Invalid Date")
102+
103+
def launchSimpleCalenderApp():
104+
root = tk.Tk()
105+
simpleCalender(root)
106+
tk.mainloop()
107+
108+
def test():
109+
launchSimpleCalenderApp()
110+
111+
if __name__ == '__main__': test()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy