Interfaces

Ejemplo (uso de boton, caja para texto, check box)

# -*- coding: utf-8 -*-
from Tkinter import *
root = Tk()
root.config(width=350, height=250)
root.title("Aplicación de escritorio en Tk")
button = Button(root, text="Hola mundo!")
button.place(x=50, y=50)
textbox = Entry(root)
textbox.insert(0, "Ingrese su nombre…")
textbox.place(x=50, y=100)
checkbox = Checkbutton(root, text="Opción 1")
checkbox.place(x=50, y=150)
root.mainloop()

Ejemplo Cafetería(uso check button para elegir el tipo de cafe)

# -*- 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()

Ejemplo (cuadros de dialogo GUI)

from Tkinter import *
from tkMessageBox import *
def main():
showinfo("Title", "Your message here")
showerror("An Error", "Oops!")
showwarning("Title", "This may not work…")
askyesno("Title", "Do you love me?")
askokcancel("Title", "Are you well?")
askquestion("Title", "How are you?")
askretrycancel("Title", "Go again?")
askyesnocancel("Title", "Are you well?")
main()
view raw cuadrosGUI.py hosted with ❤ by GitHub

Deja un comentario

Diseña un sitio como este con WordPress.com
Comenzar