![Page 1: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/1.jpg)
Python
Tkinter
Rogelio Ferreira Escutia
Profesor / InvestigadorTecnológico Nacional de MéxicoCampus Morelia
![Page 2: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/2.jpg)
Crear una ventana
![Page 3: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/3.jpg)
3
Creando una ventana
.
![Page 4: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/4.jpg)
Evitar modificar el tamaño de una ventana
![Page 5: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/5.jpg)
5
Evitar modificar el tamaño
.
resizable (se agrega antes del mainloop):
![Page 6: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/6.jpg)
Agregar etiquetas (textos)
![Page 7: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/7.jpg)
7
Agregar etiquetas Label (se requiere importar ttk)
.
![Page 8: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/8.jpg)
8
Agregar etiquetas (método 2) Label (se requiere importar ttk)
.
![Page 9: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/9.jpg)
Agregar botones
![Page 10: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/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: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/11.jpg)
11
Agregar botones Código completo:
.
![Page 12: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/12.jpg)
12
Agregar botones Ventana antes y después de generado el evento (click):
.
![Page 13: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/13.jpg)
Cajas de texto
![Page 14: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/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: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/15.jpg)
15
Agregar caja de texto Código completo:
.
![Page 16: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/16.jpg)
16
Agregar caja de texto Ventana antes y después de generado el evento (click):
.
![Page 17: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/17.jpg)
Objeto activo
![Page 18: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/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: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/19.jpg)
Deshabilitar eventos
![Page 20: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/20.jpg)
20
Deshabilitar eventos
.
configure:
![Page 21: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/21.jpg)
21
Deshabilitar eventos
.
configure:
No se puede hacer click en el evento
![Page 22: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/22.jpg)
Listas desplegables
![Page 23: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/23.jpg)
23
Listas desplegables
.
Combobox:
![Page 24: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/24.jpg)
24
Listas desplegables
.
Combobox:
![Page 25: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/25.jpg)
Botones de Control
![Page 26: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/26.jpg)
26
Botones de control
.
Checkbutton:
![Page 27: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/27.jpg)
27
Botones de control
.
Checkbutton:
![Page 28: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/28.jpg)
Botones para opciones
![Page 29: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/29.jpg)
29
Botones para opciones
.
Radiobutton (variables para colores):
![Page 30: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/30.jpg)
30
Colores
.
Lista de colores reconocidos por TK:
![Page 31: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/31.jpg)
31
Botones para opciones
.
Radiobutton:
![Page 32: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/32.jpg)
32
Botones para opciones
.
Radiobutton:
![Page 33: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/33.jpg)
33
Botones para opciones
.
Radiobutton:
Rabiobutton (rojo seleccionado):
![Page 34: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/34.jpg)
Cajas de texto(de varias líneas)
![Page 35: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/35.jpg)
35
Cajas de texto (varias líneas)
.
Importar librería:
Insertar caja de texto:
![Page 36: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/36.jpg)
36
Cajas de texto (varias líneas)
.
scrolledtext:
![Page 37: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/37.jpg)
Caja de etiquetas
![Page 38: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/38.jpg)
38
Cajas de etiquetas
.
LabelFrame - Permite ubicar varios componentes dentro de un contenedor:
![Page 39: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/39.jpg)
39
Cajas de etiquetas
.
LabelFrame - Permite ubicar varios componentes dentro de un contenedor:
![Page 40: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/40.jpg)
40
Cajas de etiquetas
.
Para colocar la posición de inicio del contenedor:
![Page 41: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/41.jpg)
Barra de Menús
![Page 42: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/42.jpg)
42
Barra de Menús
.
Importar biblioteca:
Crear Menú:
![Page 43: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/43.jpg)
43
Barra de Menús
.
Pantalla con menús:
![Page 44: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/44.jpg)
44
Barra de Menús
.
Menú con una opción y submenús:
![Page 45: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/45.jpg)
45
Barra de Menús
.
Menú con 2 opciones y línea divisoria:
![Page 46: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/46.jpg)
46
Barra de Menús
.
Menú con 2 opciones:
![Page 47: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/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: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/48.jpg)
Pestañas
![Page 49: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/49.jpg)
49
Pestañas
.
Ventana con pestaña:
![Page 50: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/50.jpg)
50
Pestañas
.
Ventana con dos pestañas:
![Page 51: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/51.jpg)
Cajas de Mensajes
![Page 52: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/52.jpg)
52
Cajas de mensajes
.
Importar librería para los mensajes (messagebox):
![Page 53: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/53.jpg)
53
Cajas de mensajes
.
Crear la barra de menús:
![Page 54: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/54.jpg)
54
Cajas de mensajes
.
Función para el manejo del evento:
![Page 55: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/55.jpg)
55
Cajas de mensajes
.
![Page 56: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/56.jpg)
56
Cajas de mensajes
.
Función para el manejo del evento:
![Page 57: Python - xumarhu.netxumarhu.net/python_tkinter.pdf · 2020. 10. 28. · Listas desplegables. ... Menú con 2 opciones y línea divisoria: 46 Barra de Menús](https://reader033.vdocuments.co/reader033/viewer/2022052814/609e026d42d6c4352d027d13/html5/thumbnails/57.jpg)
Rogelio Ferreira Escutia
Profesor / InvestigadorTecnológico Nacional de MéxicoCampus Morelia
xumarhu.net
@rogeplus
https://www.youtube.com/channel/UC0on88n3LwTKxJb8T09sGjg
rogelioferreiraescutia