Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
81 views

GUI Calculator in Python Using TKinter

This document describes a GUI calculator created using Python's Tkinter module. It defines functions for displaying numbers and operators, clearing the calculation, and evaluating the calculation. Buttons are created for each number and operator and placed in a grid layout. The buttons call the display functions. An equals button calls the calculate function to evaluate the expression and display the result. The calculator provides a simple GUI for performing basic arithmetic calculations.

Uploaded by

nhbh7579707644
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

GUI Calculator in Python Using TKinter

This document describes a GUI calculator created using Python's Tkinter module. It defines functions for displaying numbers and operators, clearing the calculation, and evaluating the calculation. Buttons are created for each number and operator and placed in a grid layout. The buttons call the display functions. An equals button calls the calculate function to evaluate the expression and display the result. The calculator provides a simple GUI for performing basic arithmetic calculations.

Uploaded by

nhbh7579707644
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

*GUI Calculator in python using TKinter……….

import tkinter

from tkinter import*

root=Tk()

root.title("Calculator")

root.geometry("570x600+100+200")

root.resizable(False,False)

root.configure(bg="#17161b")

equation=""

def show(value):

global equation

equation+=value

label_result.config(text=equation)

def clear():

global equation

equation = ""

label_result.config(text=equation)

def calculate():
global equation

result=""

if equation!="":

try:

result=eval(equation)

except:

result="error"

equation=""

label_result.config(text=result)

label_result=Label(root,width=25,height=2,text="",font=("arial",30))

label_result.pack()

Button(root,width=5,height=1, text="C",command=lambda:clear(), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#3697f5").place(x=10,y=100)

Button(root,width=5,height=1, text="/",command=lambda:show("/"), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=150,y=100)

Button(root,width=5,height=1,text="%",command=lambda:show("%"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=290,y=100)

Button(root,width=5,height=1, text="*", command=lambda:show("*"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=430,y=100)

Button(root,width=5,height=1, text="7",command=lambda:show("7"), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=10,y=200)

Button(root,width=5,height=1, text="8",command=lambda:show("8"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=150,y=200)

Button(root,width=5,height=1, text="9",command=lambda:show("9"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=290,y=200)
Button(root,width=5,height=1, text="-",command=lambda:show("-"), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=430,y=200)

Button(root,width=5,height=1, text="4",command=lambda:show("4"), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=10,y=300)

Button(root,width=5,height=1, text="5",command=lambda:show("5"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=150,y=300)

Button(root,width=5,height=1, text="6",command=lambda:show("6"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=290,y=300)

Button(root,width=5,height=1, text="+",command=lambda:show("+"), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=430,y=300)

Button(root,width=5,height=1, text="1",command=lambda:show("1"), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=10,y=400)

Button(root,width=5,height=1, text="2",command=lambda:show("2"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=150,y=400)

Button(root,width=5,height=1, text="3",command=lambda:show("3"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=290,y=400)

Button(root,width=11,height=1, text="0",command=lambda:show("0"),font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=10,y=500)

Button(root,width=5,height=1, text=".",command=lambda:show("."), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#2a2d36").place(x=290,y=500)

Button(root,width=5,height=3, text="=",command=lambda:calculate(), font=("arial",30,"bold"),bd=1,fg="#fff",bg="#fe9037").place(x=430,y=400)

root.mainloop()

You might also like