Ventanas
ventana_secundaria.py
import tkinter as tk
from tkinter import messagebox
def saludar():
[Link]("Saludo", "¡Hola!")
def sumar(a, b):
try:
return int(a) + int(b)
except ValueError:
[Link]("Error", "Ingresar solo números")
return None
def abrir_ventana_secundaria(ventana_principal):
ventana2 = [Link](ventana_principal)
[Link]("Ventana Secundaria")
[Link]("250x150")
etiqueta = [Link](ventana2, text="Soy la segunda ventana")
[Link](pady=10)
boton_saludar = [Link](ventana2, text="Saludar",
command=saludar)
boton_saludar.pack(pady=5)
boton_cerrar = [Link](ventana2, text="Cerrar",
command=[Link])
boton_cerrar.pack(pady=5)
[Link]
import tkinter as tk
from tkinter import messagebox
from ventana_secundaria import abrir_ventana_secundaria, sumar
def sumar_numeros():
a = entry_a.get()
b = entry_b.get()
resultado = sumar(a, b)
if resultado is not None:
[Link]("Resultado", f"La suma es: {resultado}")
ventana_principal = [Link]()
ventana_principal.title("Ventana Principal")
ventana_principal.geometry("300x250")
[Link](ventana_principal, text="Ejemplo con ventanas
separadas").pack(pady=10)
[Link](ventana_principal, text="Número A:").pack()
entry_a = [Link](ventana_principal)
entry_a.pack()
[Link](ventana_principal, text="Número B:").pack()
entry_b = [Link](ventana_principal)
entry_b.pack()
[Link](ventana_principal, text="Sumar",
command=sumar_numeros).pack(pady=5)
[Link](ventana_principal, text="Abrir segunda ventana",
command=lambda:
abrir_ventana_secundaria(ventana_principal)).pack(pady=5)
[Link](ventana_principal, text="Salir",
command=ventana_principal.quit).pack(pady=10)
ventana_principal.mainloop()