TKinter Python
TKinter Python
Python Tkinter
Creación de Interfaz Gráficas
1
Interfaz Gráfica con Python
Contenido
Widgets Básicos 2
Práctica 01 First Window 2
Práctica 02 Hello World with Label 3
Práctica 03 Hello World with Button 5
Práctica 04 Formulario de estudiante 6
Practica 5 Cálculo de días vividos 8
2
Interfaz Gráfica con Python
Objetivo
Código
import tkinter as tk
ventana.mainloop()
Desafío: Probar los siguientes comandos y jugar con las propiedades del objeto root
root.geometry("600x300") Tamaño
root['bg']='green'
3
Interfaz Gráfica con Python
Código
import tkinter as tk
root.geometry("600x300+500+10")
root['bg']='green'
widgetLabel.pack()
root.mainloop()
4
Interfaz Gráfica con Python
Desafío:
widgetLabel['fg']='white'
widgetLabel['font']='Arial 24'
5
Interfaz Gráfica con Python
Código
root = Tk()
#Etiqueta
#Boton
root.mainloop()
6
Interfaz Gráfica con Python
Objetivo
Código
root.geometry('500x300')
root['bg']='#ff9a52'
#Etiqueta1
labelGreeting.place(x=100, y=20)
7
Interfaz Gráfica con Python
labelGreeting['bg']='#ff9a52'
labelGreeting['fg']='#690202'
#Etiqueta2
labelNombre.place(x=10, y=60)
#Entry
entryNombre = Entry(root)
entryNombre.place(x=150, y=60)
#Boton
buttonSalir.place(x=150, y=100)
buttonSalir['width'] = '15'
root.mainloop()
Desafío
8
Interfaz Gráfica con Python
9
Interfaz Gráfica con Python
Código
from tkinter import *
win = Tk()
win.geometry("600x300")
win['bg'] = '#9dc9ac'
# Título de Formulario
labelTitle['bg'] = '#45aab8'
labelTitle['fg'] = '#39324d'
labelTitle.place(x=150, y=5)
labelEdad['bg'] = '#45aab8'
10
Interfaz Gráfica con Python
labelEdad['fg'] = '#39324d'
labelEdad.place(x=20, y=60)
edadEntry = Entry(win)
edadEntry['bg'] = '#39324d'
edadEntry['fg'] = 'white'
edadEntry.place(x=200, y=60)
labelTotal['bg'] = '#45aab8'
labelTotal['fg'] = '#39324d'
labelTotal.place(x=20, y=100)
# Despliegue de edad
totalEntry['bg'] = '#39324d'
totalEntry['fg'] = 'white'
totalEntry.place(x=200, y=100)
botonCalcular['bg'] = '#39324d'
botonCalcular['fg'] = 'white'
botonCalcular.place(x=200, y=150)
# Botón de Salir
botonSalir['bg'] = '#39324d'
11
Interfaz Gráfica con Python
botonSalir['fg'] = 'white'
botonSalir.place(x=400, y=150)
win.mainloop()
Indicar al botón la función que realizará los cálculos y establecerá valor en control entryTotal
12
Interfaz Gráfica con Python
Véase resultado
Desafío utilice un manejo de error cuando se le ingrese un dato incorrecto, mensajes de error
def calcular():
try:
except ValueError:
13
Interfaz Gráfica con Python
totalEntry.focus_set()
14
Interfaz Gráfica con Python
Cr
15