0% found this document useful (0 votes)
11 views2 pages

Simple Tkinter Calculator Code

The document contains a Python script that creates a simple calculator application using the Tkinter library. It includes functionalities for number input, basic arithmetic operations, and error handling for invalid syntax. The calculator has a graphical user interface with buttons for digits and operations, and it displays results in an entry field.

Uploaded by

rashsach1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Simple Tkinter Calculator Code

The document contains a Python script that creates a simple calculator application using the Tkinter library. It includes functionalities for number input, basic arithmetic operations, and error handling for invalid syntax. The calculator has a graphical user interface with buttons for digits and operations, and it displays results in an entry field.

Uploaded by

rashsach1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import tkinter as tk

import [Link]

from [Link] import SUNKEN

win = [Link]()

[Link]('Calculator')

frame = [Link](win, bg="skyblue", padx=10)

[Link]()

entry = [Link](frame, relief=SUNKEN, borderwidth=3, width=30)

[Link](row=0, column=0, columnspan=3, ipady=2, pady=2)

def click(num):

[Link]([Link], num)

def equal():

try:

res = str(eval([Link]()))

[Link](0, [Link])

[Link](0, res)

except:

[Link]("Error", "Syntax Error")

def clear():

[Link](0, [Link])
buttons = [

('1', 1, 0), ('2', 1, 1), ('3', 1, 2),

('4', 2, 0), ('5', 2, 1), ('6', 2, 2),

('7', 3, 0), ('8', 3, 1), ('9', 3, 2),

('0', 4, 1), ('+', 5, 0), ('-', 5, 1),

('*', 5, 2), ('/', 6, 0)

for txt, r, c in buttons:

[Link](frame, text=txt, padx=15, pady=5, width=3, command=lambda


t=txt: click(t)).grid(row=r, column=c, pady=2)

[Link](frame, text="Clear", padx=15, pady=5, width=12,


command=clear).grid(row=6, column=1, columnspan=2, pady=2)

[Link](frame, text="=", padx=15, pady=5, width=9,


command=equal).grid(row=7, column=0, columnspan=3, pady=2)

[Link]()

You might also like