Python Tkinter Interface Design Module
Tkinter is a simple and useful interface library that we can use on the backend of Python. We have created some interface objects with the Turtle module. However, Tkinter will help us in this regard, where we can easily use interface elements.

Tkinter interface is a simple and useful interface library that we can use on the backend of Python. We have created some interface objects with the Turtle module. However, Tkinter will help us in this regard, where we can easily use interface elements.
GitHub Tkinter Project: https://github.com/omersahintr/tkinter_interfaces.git
Index
- Python Tkinter Module
- Let’s Make a Simple Calculator with Tkinter
- Pack(), Place() and Grid() Positioning Methods
- padx and pady Gap Parameters
- Tkinter Text Nesnesi
- Scale Object
- Spinbox Form Object
- Checkbox Object
- Radio Button
- List Box
- End of Chapter Project-1: Body Mass Index Calculator
- End of Chapter Project-2: Secret Cryptographic Message Project with Python
Python Tkinter Module
As in many languages such as C#, JAVA or VBasic, Python also has interface designs that make it easier for users to input data and output programs. Thanks to this module, also known as User Interface, the application you write will be completely user-friendly.
Customers or employees using your application will easily perform the actions they want to do without writing any code.
Add Label
To add a label object in the Tkinter python module, write the codes in the following code line respectively.
import tkinter as tk
window = tk.Tk() # created tkinter screen.
window.title("First Screen") # Screen title set
window.minsize(width=600,height=600) # window minimum size
#label:
infoLabel = tk.Label(
text="First Label:")
infoLabel.config(bg="yellow", fg="blue",font=("Arial",30,"bold")) #Label properties
infoLabel.pack() #place location
window.mainloop() ##hold screen
Pythonconfig parameters of the infolabel object:
- bg: backround color
- fg: foreground color
- font: font type and size(takes value as tuple)
- text: text content
Screen Output:

Add Button
How to add a button object to the form screen with Python Tkinter Library?
A button object is added similar to a label object. However, it requires one more simple operation. This is to determine which command will be executed when the button is pressed. For this, a function is defined to be written to the command parameter of the button object.
import tkinter as tk
window = tk.Tk() # created tkinter screen.
window.title("First Screen") # Screen title set
window.minsize(width=600,height=600) # window minimum size
#label:
infoLabel = tk.Label(
text="First Label:")
infoLabel.config(bg="yellow", fg="blue",font=("Arial",30,"bold")) #Label properties
infoLabel.pack() #place location
#button:
def click_button(): #clicked button function has defined
infoLabel.config(text="Pressed to button") #label text parameter has changed
infoButton = tk.Button(text="Send",command=click_button) #add new button parameters
infoButton.pack() #place location
window.mainloop() ##hold screen
PythonWhen you press the Send button on the screen that opens when the code block is run, the content of the label text parameter will change.
Screen Output:

Adding an Entry (Text Box)
How to use Entry , the textbox object, which is one of the indispensable form objects, in the Tkinter Python module?
Let’s define a function and try to take the value of the text entered from the Entry object and print it into the Label object.
- The string value in Entry can be retrieved with infoEntry.get() routine.
- The infoEntry.delete(0,END) procedure clears the Entry object.
- Insert(0, “string expression“) into the Entry object with infoEntery.insert(0, “string expression“)
- With the infoEntry.focus() method, the cursor starts in this Entry object as soon as the form screen opens.
import tkinter as tk
window = tk.Tk() # created tkinter screen.
window.title("First Screen") # Screen title set
window.minsize(width=600,height=600) # window minimum size
#label:
infoLabel = tk.Label(
text="First Label:")
infoLabel.config(bg="yellow", fg="blue",font=("Arial",30,"bold")) #Label properties
infoLabel.pack() #place location
def click_button(): #clicked button function has defined
infoLabel.config(text=infoEntry.get()) #label text parameter has changed
#button:
infoButton = tk.Button(text="Send",command=click_button) #add new button parameters
infoButton.pack() #place location
#Entry:
infoEntry = tk.Entry(width=30) # Entry text object has added
infoEntry.pack()
infoEntry.focus()
window.mainloop() ##hold screen
PythonScreen Output:

Let’s Make a Simple Calculator with Tkinter
Let’s make a very simple but useful calculator with the Tkinter Python library. So that it compares the numbers entered from the form with each other and detects the possibility of a division by zero error or a negative number and calculates the four operations accordingly.
import tkinter as tk
window = tk.Tk() # created tkinter screen.
window.title("First Screen") # Screen title set
window.minsize(width=600,height=600) # window minimum size
#label:
infoLabel = tk.Label(
text="First Label:")
infoLabel.config(bg="yellow", fg="blue",font=("Arial",30,"bold")) #Label properties
infoLabel.pack() #place location
def click_button(symbol): #clicked button function has defined
equal = 0
tag = ""
numA = int(infoEntryA.get())
numB = int(infoEntryB.get())
match symbol:
case "+":
equal = numA + numB
tag = "A + B"
case "-":
if numA >= numB:
equal = numA - numB
tag = "A - B"
else:
equal = numB - numA
tag = "B - A"
case "*":
equal = numA * numB
tag = "A * B"
case "/":
if numA != 0 and numB != 0:
if numA>=numB:
equal = numA / numB
tag = "A / B"
else:
equal = numB / numA
tag = "B / A"
case _:
equal = "Error-101"
infoLabel.config(text=(tag + " = " + str(equal))) #label text parameter has changed
#Entry's:
infoEntryA = tk.Entry(width=10) # EntryA text object has added
infoEntryB = tk.Entry(width=10) # EntryB text object has added
#buttons:
infoButtonPlus = tk.Button(text="+",command = lambda:click_button("+")) #add plus action button parameters
infoButtonMinus = tk.Button(text="-", command = lambda:click_button("-")) #add minus action button parameters
infoButtonMulti = tk.Button(text="*",command=lambda:click_button("*")) #add multiple action button parameters
infoButtonDiv = tk.Button(text="/", command = lambda: click_button("/")) # add division action button parameters
#place location:
infoEntryA.pack()
infoEntryB.pack()
infoButtonPlus.pack()
infoButtonMinus.pack()
infoButtonMulti.pack()
infoButtonDiv.pack()
window.mainloop() ##hold screen
PythonScreen Output:

Although the interface is far from visual and user-friendly, we wrote a very functional calculator for the first time using the Tkinter Python Module.
Pack(), Place() and Grid() Positioning Methods
When writing Tkinter Python code, we have positioned form objects with the pack() function in the examples so far. There are other positioning methods like the pack function. Here we’ll take a look at some of them along with pack.
Pack()
Let’s look at the parameters of the pack function.
Side
Side parameter is used for alignment. It aligns left-center-right according to the width of the opened form window.
- Pack(side=”left”) : snaps to the left.
- Pack(side=”center”) : centers.
- Pack(side=”right”) : snaps to the right.
- Pack(side=”top”) : aligns to the top.
- Pack(side=”bottom”) : aligns to the bottom.
Place(x,y)
What the Place function does in the Tkinter library is it determines exactly where you want to put the form object. It takes x and y coordinate values as parameters.
- Place(x=0, y=0) : places in the upper left corner.
- Place(x=100, y=100): 100px to the right and 100px down
import tkinter as tk
window = tk.Tk() # created tkinter screen.
window.title("Simple Calculator") # Screen title set
window.minsize(width=600,height=200) # window minimum size
#label:
infoLabel = tk.Label(
text="First Label:")
infoLabel.config(bg="yellow", fg="blue",font=("Arial",30,"bold")) #Label properties
def click_button(symbol): #clicked button function has defined
equal = 0
tag = ""
numA = int(infoEntryA.get())
numB = int(infoEntryB.get())
match symbol:
case "+":
equal = numA + numB
tag = "A + B"
case "-":
if numA >= numB:
equal = numA - numB
tag = "A - B"
else:
equal = numB - numA
tag = "B - A"
case "*":
equal = numA * numB
tag = "A * B"
case "/":
if numA != 0 and numB != 0:
if numA>=numB:
equal = numA / numB
tag = "A / B"
else:
equal = numB / numA
tag = "B / A"
else:
equal = "Error-102"
case _:
equal = "Error-101"
infoLabel.config(text=(tag + " = " + str(equal))) #label text parameter has changed
#Entry's:
infoEntryA = tk.Entry(width=20) # EntryA text object has added
infoEntryB = tk.Entry(width=20) # EntryB text object has added
#buttons:
infoButtonPlus = tk.Button(text="+",command = lambda:click_button("+")) #add plus action button parameters
infoButtonMinus = tk.Button(text="-", command = lambda:click_button("-")) #add minus action button parameters
infoButtonMulti = tk.Button(text="*",command=lambda:click_button("*")) #add multiple action button parameters
infoButtonDiv = tk.Button(text="/", command = lambda: click_button("/")) # add division action button parameters
infoEntryA.place(x=20, y=10)
infoEntryB.place(x=20,y=30)
infoButtonPlus.place(x=20,y=50) #place location
infoButtonMinus.place(x=40,y=50)
infoButtonMulti.place(x=60,y=50)
infoButtonDiv.place(x=80,y=50)
infoLabel.place(x=150,y=10)
window.mainloop() ##hold screen
PythonScreen Output:

Grid(row,column)
On Tkinter Python you can work with a grid logic consisting of Rows and Columns.
Example 1:
- A.grid(row=0, column=1)
- B.grid(row=1, column=1)
- C.grid(row=2, column=1)
A |
B |
C |
Example 2:
- A.grid(row=0, column=0)
- B.grid(row=0, column=1)
- C.grid(row=0, column=2)
A | B | C |
Tkinter Python Interface Codes:
import tkinter as tk
window = tk.Tk() # created tkinter screen.
window.title("Simple Calculator") # Screen title set
window.minsize(width=600,height=200) # window minimum size
#label:
infoLabel = tk.Label(
text="First Label:")
infoLabel.config(bg="yellow", fg="blue",font=("Arial",30,"bold")) #Label properties
def click_button(symbol): #clicked button function has defined
equal = 0
tag = ""
numA = int(infoEntryA.get())
numB = int(infoEntryB.get())
match symbol:
case "+":
equal = numA + numB
tag = "A + B"
case "-":
if numA >= numB:
equal = numA - numB
tag = "A - B"
else:
equal = numB - numA
tag = "B - A"
case "*":
equal = numA * numB
tag = "A * B"
case "/":
if numA != 0 and numB != 0:
if numA>=numB:
equal = numA / numB
tag = "A / B"
else:
equal = numB / numA
tag = "B / A"
else:
equal = "Error-102"
case _:
equal = "Error-101"
infoLabel.config(text=(tag + " = " + str(equal))) #label text parameter has changed
#Entry's:
infoEntryA = tk.Entry(width=20) # EntryA text object has added
infoEntryB = tk.Entry(width=20) # EntryB text object has added
#buttons:
infoButtonPlus = tk.Button(text="+",command = lambda:click_button("+")) #add plus action button parameters
infoButtonMinus = tk.Button(text="-", command = lambda:click_button("-")) #add minus action button parameters
infoButtonMulti = tk.Button(text="*",command=lambda:click_button("*")) #add multiple action button parameters
infoButtonDiv = tk.Button(text="/", command = lambda: click_button("/")) # add division action button parameters
### GRID LOCATOR ###
infoEntryA.grid(row=0,column=0)
infoEntryB.grid(row=2,column=0)
infoButtonPlus.grid(row=1,column=1) #grid location
infoButtonMinus.grid(row=1,column=2)
infoButtonMulti.grid(row=1,column=3)
infoButtonDiv.grid(row=1,column=4)
infoLabel.grid(row=1,column=5)
window.mainloop() ##hold screen
PythonScreen Output:

It’s a good place to start, but in the future we’ll be playing around with much more user-friendly form libraries. For now, we will learn a few more features about the Tkinter Python Module.
You can review all the sample codes we wrote in my GitHub Repositories Archive. Be sure to read our articles on How to Use GitHub Version Control System and Basic Git Commands. There is information that will be very useful for your Python projects.
padx and pady Gap Parameters
You can set the spacing in x and y coordinates by writing in the config method of any form object.
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
button = Button() #new button object created
button.config(text="Resize Form", command=lambda: label.config(text="Try and Catch")) #button click action defined
button.config(bg="yellow") #button backcolor set yellow
button.config(fg="red") #button foreground color set red
button.pack() #show button
label.pack() #show label
screen.mainloop()
PythonScreen Output:

Tkinter Text Nesnesi
Unlike the Entry object, Text is a multiline text box, not a single line text box. Tkinter is extremely simple to use in Python code.
However, when retrieving data from a Text object with the get() method, you should follow a slightly different method. With Get, data can be retrieved from the Text object to a variable as follows:
- txt_variable = text.get(“1.0”, END) — Gets all lines from line 1 to the last line.
- txt_variable = text.get(“3.0”, END) — Gets all lines from line 3 to the last line.
- txt_variable = text.get(“1.3”, “5.2”) — Get all lines from line 1 to line 5.
Since the Text object in Tkinter Python contains more than one line, you need to specify which lines and how many characters of that line to start from. Although it looks like a float number type parameter, for example, the parameter“1.6” specifies to start from the 6th character of line 1.
- text.get(“1.0”, END) — Gets all lines from line 1 to the last line.
- text.delete(“1.0”,END) — Clear all content from line 1 to the last line.
- text.insert(“1.0”, “string expression“) — Insert string expression from line 1.
- text.focus() — method to move the cursor into the Text object as soon as the form is loaded.
#import tkinter as tk #
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
def txt_read(get_txt):
label.config(text=get_txt)
#Label:
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
#Button:
button = Button() #new button object created
button.config(text="Resize Form", command=lambda: label.config(text="Try and Catch")) #button click action defined
button.config(bg="yellow") #button backcolor set yellow
button.config(fg="red") #button foreground color set red
#Button2:
btn_text = Button(text="Text Read", command=lambda: txt_read(txt.get("1.0",END))) #get:row1 to END. get:"2.0" to END.
#Text object:
txt = Text(width=30,height=10)
button.pack() #show button
btn_text.pack() #show btn_text
label.pack() #show label
txt.pack() #show text
txt.focus() #txt object on focus
screen.mainloop()
PythonScreen Output:

Scale Object
Tkinter is a Python form element that has a function similar to the volume level bars of a computer. It has a feature that should be noted when retrieving data with get().
As long as you scroll up and down, it will alternate between from and to .
def select_scale(value):
label.config(text=level.get())
#import tkinter as tk #
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
def select_scale(value):
label.config(text = level.get())
#Label:
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
#Scale:
level = Scale(from_=0, to=100, command = select_scale)
label.pack() #show label
level.pack()
screen.mainloop()
PythonScreen Output:

Spinbox Form Object
Spinbox ile Python Tkinter üzerindeWhat to do with it? The Spinbox object can be used for incrementable product quantity entries.Kod satırında Spinbox kullanımını gösterelim.
#import tkinter as tk #
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
def select_spin():
label.config(text = spin.get())
#Label:
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
#Spinbox:
spin = Spinbox(from_=0, to=100, command = select_spin)
label.pack() #show label
spin.pack()
screen.mainloop()
PythonScreen Output:

Checkbox Object
It will return 1 if the Checkbox object is selected and 0 if it is not selected.
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
def run_fonk():
label.config(text=chc_val)
#Label:
label = Label() #Label object created
#Checkbox:
chc_val = tk.BooleanVar()
check = Checkbutton(text="option-1", variable=chc_val)
#Button:
button = Button(text="Run", command=run_fonk)
label.pack() #show label
check.pack()
screen.mainloop()
Python#import tkinter as tk #
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
def select_check():
label.config(text=IntVar().get())
#Label:
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
#Checkbox:
check = Checkbutton(text="option-1", variable=IntVar(), command=select_check)
label.pack() #show label
check.pack()
screen.mainloop()
PythonScreen Output:

Radio Button
How to use the Radio Button object, one of the indispensable form objects, in the Python Tkinter module?
#import tkinter as tk #
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
def select_radio():
label.config(text=radio_state.get())
#Label:
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
#Radio Buttons:
radio_state = IntVar()
radio1 = Radiobutton(text="option-1", value=1, variable=radio_state, command=select_radio)
radio2 = Radiobutton(text="option-2", value=2, variable=radio_state, command=select_radio)
label.pack() #show label
radio.pack() #show radio button
screen.mainloop()
PythonScreen Output:

List Box
The Listbox() object is used to select any of the list options. Let’s print the selected Listbox element to the Label object in the Tkinter Python module.
Here, unlike other objects, we will use the“<<ListboxSelect>>” parameter, the curselection() method and the“event” argument. We will also print the values in a list variable into the Listbox object with a for loop.
#import tkinter as tk #
from tkinter import * #different import process
screen = Tk() # screen name of Tkinter object created
screen.title("Widget Samples") #Screen title defined
screen.minsize(width=300, height=300) #screen size defined
def select_list(event):
label.config(text=list1.get(list1.curselection()))
#Label:
label = Label() #Label object created
label.config(bg="yellow") #label backcolor set yellow
label.config(fg="black") #label foreground color set black
label.config(padx=20,pady=20) #label position pad-x and pad-y
#Listbox:
list1 = Listbox()
customer_list = ["Abraham","John","Emily","Sarah","Mack","Clara"]
for i in range(len(customer_list)):
list1.insert(i,customer_list[i])
list1.bind('<<ListboxSelect>>', select_list)
label.pack() #show label
list1.pack() #show radio button
screen.mainloop()
PythonScreen Output:

End of Chapter Project-1: Body Mass Index Calculator
Using the Python Tkinter library, let’s develop an application that takes the height and weight values entered by the user through an acid form. In this application, while the user is entering data, let’s also set up a try-except block against incorrect data entry. Detect zero error and non-numeric data entry error.
Finally, let our application calculate the BMI value and make comments as underweight-normal-overweight-obese based on this value. Below, the function of each line of code is written as a description right next to it.
from tkinter import *
def bmi_calculator():
if txt_weight.get() != "0" and txt_size.get() !="0":
label_comments.config(text="")
label_results.config(text="")
try: #Error trapping to prevent an incorrect value from being returned.
bmi_weight = float(txt_weight.get()) #body weight by kg
bmi_size = float(txt_size.get()) / 100 # cm to meter converted
bmiCalculate = bmi_weight / (pow(bmi_size, 2)) # bmi calculate function
label_results.config(text=("BMI: " + str(round(bmiCalculate, 2))),bg="light blue") # float number is round 2-digits and convert to string
#Comment according to bmi values
if bmiCalculate < 16.0:
label_comments.config(text="Severe Thinness",bg="light green")
elif bmiCalculate >= 16.0 and bmiCalculate < 17.0:
label_comments.config(text="Moderate Thinness",bg="green")
elif bmiCalculate >= 17.0 and bmiCalculate < 18.5:
label_comments.config(text="Mild Thinness",bg="yellow")
elif bmiCalculate >= 18.5 and bmiCalculate < 25.0:
label_comments.config(text="Normal",bg="white")
elif bmiCalculate >= 25.0 and bmiCalculate < 30.0:
label_comments.config(text="Overweight",bg="orange")
elif bmiCalculate >= 30.0 and bmiCalculate < 35.0:
label_comments.config(text="Obese Class I",bg="red")
elif bmiCalculate >= 35.0 and bmiCalculate < 40.0:
label_comments.config(text="Obese Class II",bg="red")
elif bmiCalculate >= 40.0:
label_comments.config(text="Obese Class III",bg="red")
else:
label_comments.config(text="No Comment!",bg="red")
except ValueError:
label_comments.config(text="Just Numbers")
return
except ZeroDivisionError:
label_comments.config(text="Do not type zero!")
return
else:
label_comments.config(text="Do not type zero")
#Tkinter object:
tkScreen = Tk()
tkScreen.minsize(width=400,height=300)
tkScreen.title("Body Index Calculator - BMI")
#Labels:
label_weight = Label(text="Your Weight(kg):",fg="blue",font=("Verdana",12,"bold"))
label_size = Label(text="Your Body Size(cm):",fg="blue",font=("Verdana",12,"bold"))
label_results = Label(text="",font=("Verdana",12,"bold"))
label_comments = Label(text="",font=("Verdana",12,"bold"))
#Entries:
txt_weight = Entry(width=10)
txt_size = Entry(width=10)
btn_calc = Button(text="CALCULATE",font=("Verdana",14,"bold"),command=bmi_calculator)
###Locator###
label_weight.grid(row=0,column=0)
txt_weight.grid(row=0,column=1)
label_size.grid(row=1,column=0)
txt_size.grid(row=1,column=1)
label_results.grid(row=3,column=1)
label_comments.grid(row=4,column=1)
btn_calc.grid(row=2,column=0)
tkScreen.mainloop()
PythonScreen Output:



End of Chapter Project-2: Secret Cryptographic Message Project with Python
Using the Tkinter Python library we will create a project to generate secret and encrypted messages over a form. We need: time, stackoverflow, some google, a little bit of time and of course a computer with python installed. Let’s get started!
We define 3 different methods called Encode, Decode and File Export. Also don’t forget to import tkinter and cryptocode libraries. All steps are indicated with comment lines.
### IMPORT LIBRARY ###
from tkinter import messagebox
from tkinter import *
import cryptocode as cr
## Encoding process ##
def encode():
if txt_title.get() !="" and txt_encoding_decoding.get("1.0",END) != "" and txt_passkey.get() != "":
enc_dec = txt_encoding_decoding.get("1.0",END)
passkey = txt_passkey.get()
my_title = txt_title.get()
secret_encode = cr.encrypt(message=enc_dec,password=passkey) # Encrypt for your message.
file_export(my_title, secret_encode)
else:
messagebox.showerror(title="Uyarı!", message="Make sure you fill in all fields")
## Decoding process ##
def decode():
if txt_encoding_decoding.get("1.0", END) != "" and txt_passkey.get() != "":
enc_dec = txt_encoding_decoding.get("1.0",END)
passkey = txt_passkey.get()
secret_decode = cr.decrypt(enc_dec,password=passkey) # decrypt for your message
txt_encoding_decoding.delete("1.0",END)
txt_encoding_decoding.insert("0.0",secret_decode)
else:
messagebox.showerror(title="Uyarı!", message="Make sure you fill in all fields")
#File Saving Operations: ##
def file_export(my_title, enc_dec):
try:
file1 = open("message.txt", "a")
file1.write(my_title + "\n" + enc_dec + "\n")
file1.close()
except FileNotFoundError:
file1 = open("message.txt", "a")
file1.write(my_title + "\n" + enc_dec + "\n")
file1.close()
finally:
messagebox.showinfo("Successfuly", "The message was encrypted and saved to file.")
txt_title.delete(0, END)
txt_passkey.delete(0, END)
txt_encoding_decoding.delete("1.0", END)
lbl_status.config(text="File Saved. Did you look at the message.txt file?", bg="light green")
## UI Objects ##
screen = Tk()
screen.title("Cyrpto Text - Top Secret Messages")
screen.minsize(width=400,height=600)
screen.config(bg="light blue")
#Logo image:
img = PhotoImage(file="enigma.png")
image_label = Label(screen, image=img)
image_label.pack(padx=0,pady=45)
#Label:
lbl_title = Label(text="Title:", font=("Verdana",12,"bold"))
lbl_title.pack()
#Entry Text:
txt_title = Entry()
txt_title.pack()
txt_title.focus()
#Label:
lbl_crypto = Label(text="Encoding/Decoding:", font=("Verdana",12,"bold"))
lbl_crypto.pack()
#Text Message:
txt_encoding_decoding = Text(width=40,height=10)
txt_encoding_decoding.pack()
#Label Password Key:
lbl_password = Label(text="Passkey:", font=("Verdana",12,"bold"))
lbl_password.pack()
#Entry Passkey:
txt_passkey = Entry()
txt_passkey.pack()
#Label Status:
lbl_status = Label(text="", font=("Verdana",12,"bold"))
lbl_status.pack()
#Button Encoding and Save Action:
btn_encode = Button(text="::Encode & Save::", fg="white",bg="black", font=("Verdana",12,"bold"),command=encode)
btn_encode.pack()
#Button Decoding Action:
btn_decode = Button(text="::Decode::", fg="black",bg="white", font=("Verdana",12,"bold"),command=decode)
btn_decode.pack()
screen.mainloop()
PythonScreen Output:



Now that we have passed the end of chapter monster, we can easily move on to the next step in Python. You can share your questions about the Tkinter Python Library in the comments section below and on social media accounts.