“Interfaces Gráficas para Python con...
Transcript of “Interfaces Gráficas para Python con...
![Page 1: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/1.jpg)
“Interfaces Gráficas para Python con Tkinter”
Rogelio Ferreira Escutia
![Page 2: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/2.jpg)
Crear una ventana
![Page 3: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/3.jpg)
3
Creando una ventana
.
![Page 4: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/4.jpg)
Evitar modificar el tamaño de una ventana
![Page 5: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/5.jpg)
5
Evitar modificar el tamaño
.
resizable (se agrega antes del mainloop):
![Page 6: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/6.jpg)
Agregar etiquetas (textos)
![Page 7: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/7.jpg)
7
Agregar etiquetas Label (se requiere importar ttk)
.
![Page 8: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/8.jpg)
8
Agregar etiquetas (método 2) Label (se requiere importar ttk)
.
![Page 9: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/9.jpg)
Agregar botones
![Page 10: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/10.jpg)
10
Agregar botones Se agrega el botón:
Se le asigna una función para el manejo de su evento:
Nota: Las funciones deben agregarse antes del código principal que las manda llamar.
.
![Page 11: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/11.jpg)
11
Agregar botones Código completo:
.
![Page 12: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/12.jpg)
12
Agregar botones Ventana antes y después de generado el evento (click):
.
![Page 13: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/13.jpg)
Cajas de texto
![Page 14: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/14.jpg)
14
Agregar una caja de texto Entry:
Modificamos la función del evento para que imprima el nombre que se acaba de preguntar:
.
![Page 15: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/15.jpg)
15
Agregar caja de texto Código completo:
.
![Page 16: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/16.jpg)
16
Agregar caja de texto Ventana antes y después de generado el evento (click):
.
![Page 17: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/17.jpg)
Objeto activo
![Page 18: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/18.jpg)
18
Objeto activo
.
focus (se agrega antes del mainloop y nos define cual de los objetos de la interfaz gráfica estará activo cuando se arranque la interfaz:
![Page 19: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/19.jpg)
Deshabilitar eventos
![Page 20: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/20.jpg)
20
Deshabilitar eventos
.
configure:
![Page 21: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/21.jpg)
21
Deshabilitar eventos
.
configure:No se puede hacer click en el evento
![Page 22: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/22.jpg)
Listas desplegables
![Page 23: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/23.jpg)
23
Listas desplegables
.
Combobox:
![Page 24: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/24.jpg)
24
Listas desplegables
.
Combobox:
![Page 25: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/25.jpg)
Botones de Control
![Page 26: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/26.jpg)
26
Botones de control
.
Checkbutton:
![Page 27: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/27.jpg)
27
Botones de control
.
Checkbutton:
![Page 28: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/28.jpg)
Botones para opciones
![Page 29: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/29.jpg)
29
Botones para opciones
.
Radiobutton (variables para colores):
![Page 30: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/30.jpg)
30
Colores
.
Lista de colores reconocidos por TK:
![Page 31: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/31.jpg)
31
Botones para opciones
.
Radiobutton:
![Page 32: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/32.jpg)
32
Botones para opciones
.
Radiobutton:
![Page 33: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/33.jpg)
33
Botones para opciones
.
Radiobutton:
Rabiobutton (rojo seleccionado):
![Page 34: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/34.jpg)
Cajas de texto(de varias líneas)
![Page 35: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/35.jpg)
35
Cajas de texto (varias líneas)
.
Importar librería:
Insertar caja de texto:
![Page 36: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/36.jpg)
36
Cajas de texto (varias líneas)
.
scrolledtext:
![Page 37: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/37.jpg)
Caja de etiquetas
![Page 38: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/38.jpg)
38
Cajas de etiquetas
.
LabelFrame - Permite ubicar varios componentes dentro de un contenedor:
![Page 39: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/39.jpg)
39
Cajas de etiquetas
.
LabelFrame - Permite ubicar varios componentes dentro de un contenedor:
![Page 40: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/40.jpg)
40
Cajas de etiquetas
.
Para colocar la posición de inicio del contenedor:
![Page 41: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/41.jpg)
Barra de Menús
![Page 42: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/42.jpg)
42
Barra de Menús
.
Importar biblioteca:
Crear Menú:
![Page 43: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/43.jpg)
43
Barra de Menús
.
Pantalla con menús:
![Page 44: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/44.jpg)
44
Barra de Menús
.
Menú con una opción y submenús:
![Page 45: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/45.jpg)
45
Barra de Menús
.
Menú con 2 opciones y línea divisoria:
![Page 46: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/46.jpg)
46
Barra de Menús
.
Menú con 2 opciones:
![Page 47: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/47.jpg)
47
Barra de Menús (salir)
.
Evento salir (se modifica el menú para el manejo del evento):
Se agrega la función para el manejo del evento
![Page 48: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/48.jpg)
Pestañas
![Page 49: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/49.jpg)
49
Pestañas
.
Ventana con pestaña:
![Page 50: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/50.jpg)
50
Pestañas
.
Ventana con dos pestañas:
![Page 51: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/51.jpg)
Cajas de Mensajes
![Page 52: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/52.jpg)
52
Cajas de mensajes
.
Importar librería para los mensajes (messagebox):
![Page 53: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/53.jpg)
53
Cajas de mensajes
.
Crear la barra de menús:
![Page 54: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/54.jpg)
54
Cajas de mensajes
.
Función para el manejo del evento:
![Page 55: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/55.jpg)
55
Cajas de mensajes
.
![Page 56: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/56.jpg)
56
Cajas de mensajes
.
Función para el manejo del evento:
![Page 57: “Interfaces Gráficas para Python con Tkinter”sagitario.itmorelia.edu.mx/~rogelio/python_tkinter.pdf10 Agregar botones Se agrega el botón: Se le asigna una función para el manejo](https://reader034.fdocumento.com/reader034/viewer/2022042319/5f08eec07e708231d4246cc2/html5/thumbnails/57.jpg)
Rogelio Ferreira Escutia
Instituto Tecnológico de MoreliaDepartamento de Sistemas y Computación
Correo: [email protected] [email protected]
Página Web: http://sagitario.itmorelia.edu.mx/~rogelio/http://www.xumarhu.net/
Twitter: http://twitter.com/rogeplusFacebook: http://www.facebook.com/groups/xumarhu.net/