PYTHON
LESSON 11
INTRODUCTION TO TKINTER
Dear Parents
Today your child learned and practiced:
Using TKinter library to make a Creating button components to have
graphical software an interactivity in the screen
Creating label components to have a Creating a simple graphical software
text in the screen using the components learned
Those skills benefit student’s development by:
Getting used to text-based Knowledge of using the tkinter library
programming and the components
Knowledge of how to create a Improving programming skills
software with graphic element.
Example of Project:
JuniorKoders@2019
1
Main Objective: In this lesson, student learn how to make a program that have graphic so
the user can interact with the program. To do so, student need to use a specific library
which is TKinter library. TKinter library offer functionalities to make a graphical software.
Student learn how to create the window of the program and add components to it such as
label and button. Image above show one of the project done by student in this lesson where
student try to practice creating label and button to their program. Student also add
functionality to the button so when the button is clicked, the program will do a function
assigned to the button.
Key Concepts:
To start creating graphical software, we need to import the necessary library which is TKinter
library. Before creating the components of the software, the window should always be
created first. To create a window, we can use the command “[Link]()” and store it inside
a variable so it can be called an object which will be used later on. After creating the window,
we can give title to it using “[Link](“text”)” or change the size of the window using
“[Link](“widthxheight”)”. Lastly, we need to use “[Link]()” to let the
computer know that the graphic should be created.
To create label component in the window, we can use the command “[Link](window,
text=”text shown in label”)” and store it inside a variable so it can become an object for later
use. After creating the component, it is important that we use a command that place it into
the target window.
JuniorKoders@2019
1
To place the components we already make into the window, we can use 3 commands to do
so. First, we can use the command “[Link]()” to place the component. When using
pack(), the component will be automatically placed by the computer to the middle of the
screen. We have several configuration we can add to the pack() placement to modify the
position of the component.
Second, we can use the command “[Link](column = number, row = number)” to place a
component in the window. By using grid() command, we are placing the components in a
table and that is why the grid() command require column and row number. The placement
always try to fill the empty slot in the table so we can’t jump column or row. We can also add
configuration to the command to affect the positioning of the components.
Lastly, we can use the command “[Link](x = number, y =number)” to place a component
in the window. By using place() command, we can place a component in the window based
on the coordinates system where 0, 0 will be located in the top left of the window. We can
also add configuration to the command to affect the positioning of the component.
JuniorKoders@2019
2
To create a button, we can use the command “[Link](window, text=”what to show
text”)” where we can store inside a variable so it can become an object for later use. By having
a button in our program, we can have interactivity between user and the program.
To make the button do a command, we need to make it into a function first before it can be
connected to the button. After making the function, we are linking the function to the button
by adding “command=functioname” so when the button is clicked, it will do the command
assigned to it. Make sure that when giving the command to the button, we just give the
function name without bracket because the command will not take any argument.
How to revise the material at home:
Practice the commands learned on this lesson by creating a simple program.
Try to tinker around with different method of placement of component.
Practice by creating multiple labels and buttons.
Did you know that…
Python is a programming language suitable for beginners as it requires accuracy and
attentiveness of the user. Using Python, programmer can make graphical software and game
using the library provided in Python programming language. Non-programmer such as data
analyst also use python to make a simple program to process the data.
Please note that we adjust pace of our courses to students’ needs and some students might need more practice to learn and
some receive extra tasks which might not be included in this information sheet.
JuniorKoders@2019
3