martes, 29 de octubre de 2019

CheckButton Ejemplo 1

# -*- coding: utf-8 -*-
from Tkinter import *
def seleccionar():
cadena = ""
if (leche.get()):
cadena += "Con leche"
else:
cadena += "Sin leche"
if (azucar.get()):
cadena += " y con azúcar"
else:
cadena += " y sin azúcar"
monitor.config(text=cadena)
# Configuración de la raíz
root = Tk()
root.title("Cafetería")
root.config(bd=15)
leche = IntVar() # 1 si, 0 no
azucar = IntVar() # 1 si, 0 no
imagen = PhotoImage(file="image.gif")
Label(root, image=imagen).pack(side="left")
frame = Frame(root)
frame.pack(side="left")
Label(frame, text="¿Cómo quieres el café?").pack(anchor="w")
Checkbutton(frame, text="Con leche", variable=leche, onvalue=1,
offvalue=0, command=seleccionar).pack(anchor="w")
Checkbutton(frame, text="Con azúcar", variable=azucar, onvalue=1,
offvalue=0, command=seleccionar).pack(anchor="w")
monitor = Label(frame)
monitor.pack()
# Finalmente bucle de la aplicación
root.mainloop()
view raw checkbotton2.py hosted with ❤ by GitHub

No hay comentarios:

Publicar un comentario