Python Tkinter GUI Development Guide
Python Tkinter GUI Development Guide
Python Tkinter
Creation of Graphical Interfaces
1
Graphical Interface with Python
Content
Basic Widgets 2
Worktca 01 First Window 2
Worktca 02 Hello World with Label 3
Worktca 03 Hello World with Buton 5
Worktca 04 Student form 6
Worktabout 5 Calculation of days lived 8
2
Graphical Interface with Python
Objective
Code
import tkinter as tk
[Link]()
Challenge: Try the following commands and play with the properties of the root object
[Link]("600x300") Size
root['bg']='green'
3
Graphic Interface with Python
Code
import tkinter as tk
[Link]('600x300+500+10')
root['bg']='green'
[Link]()
[Link]()
4
Graphical Interface with Python
Desafoo
widgetLabel['fg']='white'
widgetLabel['font']='Arial 24'
5
Graphical Interface with Python
Code
root = Tk()
#Label
Hello World!
Button
[Link]()
6
Graphical Interface with Python
Object
Code
[Link]('500x300')
root['bg']='#ff9a52'
#Label1
[Link](x=100, y=20)
7
Graphical Interface with Python
labelGreetng['bg']='#ff9a52'
labelGreetng['fg']='#690202'
#Label2
[Link](x=10, y=60)
Entry
entryNombre = Entry(root)
[Link](x=150, y=60)
#Button
[Link](x=150, y=100)
buuonSalir['width'] = '15'
[Link]()
Dare
8
Graphical Interface with Python
9
Graphic Interface with Python
Code
from tkinter import *
win = Tk()
[Link]("600x300")
win['bg'] = '#9dc9ac'
# Título de Formulario
labelTitle['bg'] = '#45aab8'
labelTitle['fg'] = '#39324d'
[Link](x=150, y=5)
labelEdad['bg'] = '#45aab8'
10
Graphical Interface with Python
labelEdad['fg'] = '#39324d'
[Link](x=20, y=60)
edadEntry = Entry(win)
edadEntry['bg'] = '#39324d'
edadEntry['fg'] = 'white'
[Link](x=200, y=60)
labelTotal['bg'] = '#45aab8'
labelTotal['fg'] = '#39324d'
[Link](x=20, y=100)
Age distribution
totalEntry['bg'] = '#39324d'
totalEntry['fg'] = 'white'
[Link](x=200, y=100)
botonCalcular['bg'] = '#39324d'
botonCalcular['fg'] = 'white'
[Link](x=200, y=150)
Exit Button
botonSalir['bg'] = '#39324d'
11
Graphic Interface with Python
botonSalir['fg'] = 'white'
[Link](x=400, y=150)
[Link]()
Indicate to the button the function that will perform the calculations and set the value in control entryTotal.
12
Graphic Interface with Python
See result
Challenge to utilize error handling when incorrect data is entered, error messages
def calculate():
try:
except ValueError:
13
Graphical Interface with Python
[Link](message="Error en el datos",ttle="Error")
totalEntry.focus_set()
14
Graphical Interface with Python
Cr
15