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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | #!/usr/bin/python # -*- coding: utf-8 -*- # # ---------------- READ ME --------------------------------------------- # This Script is Created Only For Practise And Educational Purpose Only # This is an Example Of Tkinter Canvas Graphics # This Script Is Created For http://www.bitforestinfo.com # This Script is Written By __author__='''
###################################################### By ######################################################
Suraj Singh surajsinghbisht054@gmail.com http://www.bitforestinfo.com/
###################################################### ''' print __author__ try: import Tkinter except: import tkinter as Tkinter import dob
# Format printdate = """ Date : \t{0:%d} Month : \t{0:%B} Year : \t{0:%Y} Day : \t{0:%A} Hour : \t{0:%I} Minute : \t{0:%M} Second : \t{0:%S} Period : \t{0:%p}
Standard Date {0:%d}/{0:%B}/{0:%Y} {0:%A} {0:%I}:{0:%M}:{0:%S} {0:%p} """ printage="""Age In Days : {} Days In Year : {} Years {} days """
def main(): root=Tkinter.Tk(className=" Age Calculator") storeobj=MFrame(root, text="Input Fields") storeobj.pack(padx=20,pady=20,ipadx=20,ipady=20,expand="yes",fill='both')
storeobj1=NFrame(root, text="Output Fields") storeobj1.pack(padx=20,pady=20,ipadx=20,ipady=20,expand="yes",fill='both') main_variable = Tkinter.StringVar() main_variable.set(printdate) storeobj.main_variable = main_variable storeobj1.main_variable = main_variable storeobj1.create_label() root.mainloop() return
class MFrame(Tkinter.LabelFrame): def __init__(self, *args, **kwargs): Tkinter.LabelFrame.__init__(self,*args, **kwargs) self.main_variable=None self.all_function_trigger()
def all_function_trigger(self): self.create_variables() self.create_labels_() self.create_date_spin_box() self.create_time_spin_box() self.create_excecute_button() return
def run_command(self): lt=[] for i in self.variables: lt.append(i.get()) data= [i.get().rjust(2,"0") for i in self.variables] age,born,today = dob.age(data) self.main_variable.set(printdate.format(born)+printage.format(age,str(divmod(int(age),365)[0]),str(divmod(int(age),365)[1]))) print self.main_variable.get() return
def create_excecute_button(self): Tkinter.Button(self,text="Calculate",width=15, command=self.run_command, relief="raised").grid(row=10, column=0, columnspan=6) return
def create_variables(self): self.variables=[] for i in [1,1,1970,1,59,59]: storeobj=Tkinter.StringVar() storeobj.set(i) self.variables.append(storeobj) return
def create_date_spin_box(self): Tkinter.Label(self, text="dd/mm/yyyy").grid(row=1,column=0) Tkinter.Spinbox(self, from_=1,to_=31, width=3, textvariable=self.variables[0]).grid(row=1, column=1) Tkinter.Label(self, text="/").grid(row=1, column=2) Tkinter.Spinbox(self, from_=1,to_=12, width=3, textvariable=self.variables[1]).grid(row=1, column=3) Tkinter.Label(self, text="/").grid(row=1, column=4) Tkinter.Entry(self, width=6, textvariable=self.variables[2]).grid(row=1, column=5) return
def create_time_spin_box(self): Tkinter.Label(self, text="hh:mm:ss").grid(row=5,column=0) Tkinter.Spinbox(self, from_=1,to_=24, width=3, textvariable=self.variables[3]).grid(row=5, column=1) Tkinter.Label(self, text=":").grid(row=5, column=2) Tkinter.Spinbox(self, from_=1,to_=60, width=3, textvariable=self.variables[4]).grid(row=5, column=3) Tkinter.Label(self, text=":").grid(row=5, column=4) Tkinter.Spinbox(self, from_=1,to_=60, width=3, textvariable=self.variables[5]).grid(row=5, column=5) return
def create_labels_(self): Tkinter.Label(self, text="Date").grid(row=0, column=0, columnspan=4) Tkinter.Label(self, text="Time").grid(row=3, column=0, columnspan=4) return
class NFrame(Tkinter.LabelFrame): def __init__(self, *args, **kwargs): Tkinter.LabelFrame.__init__(self, *args, **kwargs) self.main_variable=None
def create_label(self): Tkinter.Label(self, textvariable=self.main_variable, justify="left").pack() return
if __name__ == '__main__': main()
|