Lo siento si el código anterior no cumplió con tus expectativas en términos de diseño. A continuación, te muestro una versión mucho más avanzada y con un diseño más profesional de una calculadora usando tkinter.
import tkinter as tk
class Calculadora(tk.Tk):
def __init__(self):
super().__init__()
self.title("Calculadora Básica")
self.geometry("400x400")
self.resultado_label = tk.Label(self, text="", font=("Arial", 24), bg="white", relief="solid", bd=2, anchor="e")
self.resultado_label.pack(pady=20, fill="x")
self.entry = tk.Entry(self, font=("Arial", 24), bg="white", relief="solid", bd=2)
self.entry.pack(pady=10, fill="x")
self.buttons = {}
for i in range(9):
self.buttons[str(i)] = tk.Button(self, text=str(i), font=("Arial", 18), bg="#f2f2f2", relief="solid", bd=2, command=lambda i=i: self.on_button_click(i))
self.buttons[str(i)].pack(fill="x")
self.buttons["0"] = tk.Button(self, text="0", font=("Arial", 18), bg="#f2f2f2", relief="solid", bd=2, command=lambda: self.on_button_click(0))
self.buttons["0"].pack(fill="x")
self.buttons["+"] = tk.Button(self, text="+", font=("Arial", 18), bg="#ff7f50", fg="white", relief="solid", bd=2, command=lambda: self.on_button_click("+"))
self.buttons["+"].pack(fill="x")
self.buttons["-"] = tk.Button(self, text="-", font=("Arial", 18), bg="#ff7f50", fg="white", relief="solid", bd=2, command=lambda: self.on_button_click("-"))
self.buttons["-"].pack(fill="x")
self.buttons["*"] = tk.Button(self, text="*", font=("Arial", 18), bg="#ff7f50", fg="white", relief="solid", bd=2, command=lambda: self.on_button_click("*"))
self.buttons["*"].pack(fill="x")
self.buttons["/"] = tk.Button(self, text="/", font=("Arial", 18), bg="#ff7f50", fg="white", relief="solid", bd=2, command=lambda: self.on_button_click("/"))
self.buttons["/"].pack(fill="x")
self.buttons["="] = tk.Button(self, text="=", font=("Arial", 18), bg="#ff7f50", fg="white", relief="solid", bd=2, command=self.calcular)
self.buttons["="].pack(fill="x")
self.operador = None
self.num1 = None
self.num2 = None
def on_button_click(self, button):
if button == "+":
self.operador = "+"
self.num1 = float(self.entry.get())
self.entry.delete(0, tk.END)
elif button == "-":
self.operador = "-"
self.num1 = float(self.entry.get())
self.entry.delete(0, tk.END)
elif button == "*":
self.operador = "*"
self.num1 = float(self.entry.get())
self.entry.delete(0, tk.END)
elif button == "/":
self.operador = "/"