|
| 1 | +# import all functions/classes from the tkinter |
| 2 | +from tkinter import * |
| 3 | +from tkinter import ttk |
| 4 | + |
| 5 | +exp = " " |
| 6 | +def press(num): |
| 7 | + global exp |
| 8 | + exp+=str(num) |
| 9 | + equation.set(exp) |
| 10 | + |
| 11 | +# Function for clearing the |
| 12 | +# contents of all text entry boxes |
| 13 | +def clear (): |
| 14 | + global exp |
| 15 | + exp = " " |
| 16 | + equation.set(" ") |
| 17 | + |
| 18 | +#function to calculate the tax it values are default , could varie from time to time. |
| 19 | +def taxamount(income): |
| 20 | + totalamount=0 |
| 21 | + tax=0 |
| 22 | + if income <= 500000: |
| 23 | + tax = 0 |
| 24 | + |
| 25 | + elif income <= 1000000: |
| 26 | + tax = 12500 + (income) * 0.20 |
| 27 | + |
| 28 | + elif income >= 1000001: |
| 29 | + tax = 112500 + (income) * 0.30 |
| 30 | + else: |
| 31 | + tax = 12500+100000+(income - 1000000)* 0.3 |
| 32 | + |
| 33 | + totalamount=tax |
| 34 | + return totalamount |
| 35 | + |
| 36 | +# take a value from the respective entry boxes |
| 37 | +# get method returns current text as string |
| 38 | +def butter(): |
| 39 | + income=IntVar() |
| 40 | + income=incomefield.get() |
| 41 | + entryField.delete(0,'end') |
| 42 | + amount = taxamount(int(income)) |
| 43 | + print(amount) |
| 44 | + entry.set(str(amount)) |
| 45 | + |
| 46 | + |
| 47 | + # Create a GUI window |
| 48 | +root=Tk() |
| 49 | + |
| 50 | + |
| 51 | +# Set the background colour of GUI window |
| 52 | +root.configure(background="lightgrey") |
| 53 | +root.resizable(0,0) |
| 54 | + |
| 55 | +# Set the configuration of GUI window |
| 56 | +root.geometry('300x280') |
| 57 | + |
| 58 | +# set the name of tkinter GUI window |
| 59 | +root.title("income Tax Calculator") |
| 60 | + |
| 61 | +entry= StringVar() |
| 62 | +equation = StringVar() |
| 63 | + |
| 64 | +# ************************************************************************* |
| 65 | +inputField = Frame(root) |
| 66 | +inputField.place(x=20,y=10) |
| 67 | + |
| 68 | +# Create a Original your income: label |
| 69 | +labelincome = Label(inputField,text="Your Income",background="royalblue",width=12,foreground="White") |
| 70 | +labelincome.grid(row=0, column=0) |
| 71 | +incomefield = Entry(inputField,textvariable = equation, width = 20,background="SkyBlue2",foreground="black",justify=CENTER) |
| 72 | +incomefield.grid(row=0,column=1) |
| 73 | + |
| 74 | +# Create a Original Total tax: label |
| 75 | +totaltax = Label(inputField,text="Total Tax",background="royalblue",width=12,foreground="white") |
| 76 | +totaltax.grid(row=1,column=0) |
| 77 | +entryField = Entry(inputField,textvariable = entry, width = 20,background="Yellowgreen",foreground="black",justify=CENTER) |
| 78 | +entryField.grid(row=1,column=1) |
| 79 | + |
| 80 | +# ************************************************************************* |
| 81 | +findTaxFrame = Frame(root) |
| 82 | +findTaxFrame.place(x=20,y=80) |
| 83 | + |
| 84 | +# Create a Button to click to make the caculation. |
| 85 | +button = Button(findTaxFrame,text="Find Income Tax", width = 30,activebackground="cyan",background='skyblue', command=butter) |
| 86 | +button.grid(row=2,column=0,columnspan=3) |
| 87 | + |
| 88 | +# ************************************************************************* |
| 89 | + |
| 90 | +#Creating the buttons from 1 - 9 and 0 in GUI window to enter the number. |
| 91 | +numpadFrame = Frame(root) |
| 92 | +numpadFrame.place(x=20,y=120) |
| 93 | + |
| 94 | +btn9 = ttk.Button(numpadFrame, text = '9' , width = 10 , command = lambda : press(9) ) |
| 95 | +btn9.grid(row=0,column=0) |
| 96 | + |
| 97 | +btn8 = ttk.Button(numpadFrame, text = '8' , width = 10 , command = lambda : press(8) ) |
| 98 | +btn8.grid(row=0,column=1) |
| 99 | + |
| 100 | +btn7 = ttk.Button(numpadFrame, text = '7' , width = 10 , command = lambda : press(7) ) |
| 101 | +btn7.grid(row=0,column=2) |
| 102 | + |
| 103 | +btn6 = ttk.Button(numpadFrame, text = '6' , width = 10 , command = lambda : press(6) ) |
| 104 | +btn6.grid(row=1,column=0) |
| 105 | + |
| 106 | +btn5 = ttk.Button(numpadFrame, text = '5' , width = 10 , command = lambda : press(5) ) |
| 107 | +btn5.grid(row=1,column=1) |
| 108 | + |
| 109 | +btn4 = ttk.Button(numpadFrame, text = '4' , width = 10 , command = lambda : press(4) ) |
| 110 | +btn4.grid(row=1,column=2) |
| 111 | + |
| 112 | +btn3 = ttk.Button(numpadFrame, text = '3' , width = 10, command = lambda : press(3) ) |
| 113 | +btn3.grid(row=2,column=0) |
| 114 | + |
| 115 | +btn2 = ttk.Button(numpadFrame, text = '2' , width = 10, command = lambda : press(2) ) |
| 116 | +btn2.grid(row=2,column=1) |
| 117 | + |
| 118 | +btn1 = ttk.Button(numpadFrame, text = '1' , width = 10 , command = lambda : press(1) ) |
| 119 | +btn1.grid(row=2,column=2) |
| 120 | + |
| 121 | +zeroAndClearFrame = Frame(root) |
| 122 | +zeroAndClearFrame.place(x=20,y=220) |
| 123 | + |
| 124 | +btn0= ttk.Button(zeroAndClearFrame, text = '0' , width = 10, command = lambda : press(0) ) |
| 125 | +btn0.grid(row=3,column=0) |
| 126 | + |
| 127 | +#Creating the buttons CLEAR to clear the txt boxes. |
| 128 | +btnclr = Button(zeroAndClearFrame, text = 'Clear' , width = 19, background='orange', activebackground='red',activeforeground='white', command = clear ) |
| 129 | +btnclr.grid(row=3,column=1) |
| 130 | + |
| 131 | +# Start the GUI |
| 132 | +root.mainloop() |
0 commit comments