0% found this document useful (0 votes)
3 views1 page

Test 1

This document contains a Python script that creates a scientific calculator using the Tkinter library. It includes buttons for various mathematical functions and operations, allowing users to input expressions and evaluate them. The calculator handles errors and provides a clear interface for user interaction.

Uploaded by

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

Test 1

This document contains a Python script that creates a scientific calculator using the Tkinter library. It includes buttons for various mathematical functions and operations, allowing users to input expressions and evaluate them. The calculator handles errors and provides a clear interface for user interaction.

Uploaded by

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

import tkinter as tk

from math import *

def click(event):
text = event.widget.cget("text")
if text == "=":
try:
result = eval(str(screen.get()))
screen_var.set(result)
except Exception as e:
screen_var.set("Error")
elif text == "C":
screen_var.set("")
else:
screen_var.set(screen_var.get() + text)

root = tk.Tk()
root.geometry("400x600")
root.title("Calculadora Científica")

screen_var = tk.StringVar()
screen = tk.Entry(root, textvar=screen_var, font="Arial 20")
screen.pack(fill=tk.X, ipadx=8, pady=10, padx=10)

buttons = [
["sin", "cos", "tan", "sqrt"],
["log", "exp", "pow", "pi"],
["7", "8", "9", "/"],
["4", "5", "6", "*"],
["1", "2", "3", "-"],
["0", ".", "C", "+"],
["(", ")", "=", ""]
]

for row in buttons:


f = tk.Frame(root)
for btn in row:
b = tk.Button(f, text=btn, padx=20, pady=20, font="Arial 18")
b.pack(side=tk.LEFT, expand=True, fill="both")
b.bind("<Button-1>", click)
f.pack()

root.mainloop()

You might also like