How I created my first CALCULATOR using python programming!!! (Extremely Basic)
Basically, I used a module of python package that is Tkinter. Tkinter is basically a module in python used to create GUIs (Graphical User Interface). Through this module , you can create small apps , your own notepad , small games like tic tac toe, etc. You can download Python latest version from the link given below .
LINK - https://www.python.org/downloads/
I use visual studio code editor for editing my code. Most programmers use this editor . You can download it from https://code.visualstudio.com/download .
After the installation of python , you can install the tkinter module using the following command - pip install tkinter , After the installation , You are good to go .
You can read tkinter python documentation from https://docs.python.org/3/library/tk.html and then you are good to go . I will provide the source code of my calculator . It is extremely basic.
source code :
from tkinter import *
import time
root = Tk()
root.geometry('600x400')
root.title('First Program')
x = IntVar()
y = IntVar()
entry_1 = Entry(root,textvariable=x)
entry_2 = Entry(root,textvariable=y)
entry_1.pack()
entry_2.pack()
def add():
name = int(entry_1.get())+int(entry_2.get())
sent = f'{entry_1.get()} + {entry_2.get()} = {name}'
print(sent)
bc = Label(text=sent,bg='black',fg='white')
bc.pack()
def sub():
name = int(entry_1.get())-int(entry_2.get())
sent = f'{entry_1.get()} - {entry_2.get()} = {name}'
print(sent)
bc = Label(text=sent,bg='black',fg='white')
bc.pack()
def mult():
name = int(entry_1.get())*int(entry_2.get())
sent = f'{entry_1.get()} x {entry_2.get()} = {name}'
print(sent)
bc = Label(text=sent,bg='black',fg='white')
bc.pack()
def div():
name = int(entry_1.get())/int(entry_2.get())
sent = f'{entry_1.get()} / {entry_2.get()} = {name}'
print(sent)
bc = Label(text=sent,bg='black',fg='white')
bc.pack()
def back():
txt = 'Thank you for using the calculator'
bt = Label(text=txt,bg='black',fg='white')
bt.pack()
print(txt)
root_2 = Tk()
root_2.geometry('200x100')
xy = Label(root_2,text='Are you sure you want to quit ? ',bg='black',fg='white')
xy.pack()
xyz = Button(root_2,text='Quit',bg='black',fg='white',command=root.quit)
xyz.pack()
root_2.quit()
root_2.mainloop()
addition = Button(text='+',bg='white',fg='black',command=add)
subtraction = Button(text='-',bg='white',fg='black',command=sub)
multiply = Button(text='x',bg='white',fg='black',command=mult)
divide = Button(text='/',bg='white',fg='black',command=div)
Q = Button(text='Quit',bg='white',fg='black',command=back)
addition.pack()
subtraction.pack()
multiply.pack()
divide.pack()
Q.pack()
root.mainloop()
You can copy this source code if you want!!!...If you have reached till here . Thank you so much for reading this blog. Have a nice day!!!
Thank you for the source code
ReplyDelete