Build a basic Text Editor using Tkinter in Python
Last Updated :
29 Dec, 2020
Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but this is the only framework that’s built into the Python standard library. It has several strengths; it’s cross-platform, so the same code works on Windows, macOS, and Linux. It is lightweight and relatively painless to use compared to other frameworks. This makes it a compelling choice for building GUI applications in Python, especially for applications where a modern shine is unnecessary, and the top priority is to build something that’s functional and cross-platform quickly.
Let’s start quickly working with Tkinter
Let’s Understand the Basics
Firstly Tkinter is a module that is available in most IDE’s. So let’s break apart the beginning into points:
- Importing the Tkinter module.
- Creating a window in which the program executes. It is also known as the “root window”.
- Finally, using a function to execute the code which is known as “mainloop()”.
Python3
from tkinter import *
root = Tk()
root.mainloop()
|
Output:

“*” implements all features of Tkinter
This is how you could build a window in just three simple lines!
Note: Please do not spell “tkinter” as with a capital “T”, as this would not import the module and you would most probably encounter an error message!!!
Designing Our GUI Window
This is a simple step! So we will basically use these mains functions:-
- geometry(“AAAxBBB”)
- minsize(height = AAA, width = BBB)
- maxsize(height = AAA, width = BBB)
- title(“DESIRED TITLE”)
Python3
from tkinter import *
root = Tk()
root.geometry( "300x300" )
root.minsize(height = 560 )
root.title( "TKINter Program" )
root.mainloop()
|
Output:

Create a Basic Notepad
Notepad is one thing used commonly by every person who owns a desktop. It a shortcut tool to save important information in small notes, for temporary purposes, etc. Let’s make our own notepad using Tkinter.
First, let’s type the basic code that we discussed earlier.
Python3
from tkinter import *
root = Tk()
root.geometry( "300x300" )
root.minsize(height = 560 )
root.title( "Notepad" )
root.mainloop()
|
Okay so let’s think we will need a text function and a scroll bar to scroll through the text if it exceeds the dimensions of the window. Also, we learn about grid() and pack(). They are used to pack the functions in the window, without them the buttons, text, frames would not display in the window.
Note: We can either use .grid() or .pack() for our program. However, using both in the same file would not work since Tkinter does not accept this, you obtain an error. You could use .pack() for efficient packing
Now let’s add a scrollbar: We shall invent a variable known as scrollbar and equate it to Scrollbar(root). It is important to add root into the brackets to integrate the scrollbar function into main root loop.
Now let’s pack the scrollbar: We call the variable name and append it with “.pack(). We use side = RIGHT so that the scrollbar is added to the right of the window and fill = Y or fill = “y” (Use anyone) so that it fill across the whole y-axis.
Python3
from tkinter import *
root = Tk()
root.geometry( "300x300" )
root.minsize(height = 560 ,
width = 560 )
root.title( "Notepad" )
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT,
fill = Y)
root.mainloop()
|
Output:

Now let’s add the text: We will use the text function and pack it. Also, we will configure the scrollbar for functionality. We will add a command called “yscrollcommand” which will connect the text and scrollbar function together and it would add scrolling option for the text.
Python3
from tkinter import *
root = Tk()
root.geometry( "350x250" )
root.title( "Sticky Notes" )
root.minsize(height = 250 , width = 350 )
root.maxsize(height = 250 , width = 350 )
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT,
fill = Y)
text_info = Text(root,
yscrollcommand = scrollbar. set )
text_info.pack(fill = BOTH)
scrollbar.config(command = text_info.yview)
root.mainloop()
|
Output:

Similar Reads
Python - UwU text convertor GUI using Tkinter
Prerequisites :Introduction to tkinter | UwU text convertor Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with T
4 min read
Python Tkinter â How to display a table editor in a text widget?
In this article, we will discuss how to display a table editor in a text widget. Before moving ahead let's create a simple text widget first with the help of Tkinter. For the link to the Excel file used in the code Text WidgetThe Text widget is used to show the text editor in the Tkinter window. A u
3 min read
Python | Loan calculator using Tkinter
Prerequisite: Tkinter Introduction Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest
5 min read
Python: Age Calculator using Tkinter
Prerequisites :Introduction to tkinter Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fa
5 min read
Sentiment Detector GUI using Tkinter - Python
Prerequisites : Introduction to tkinter | Sentiment Analysis using Vader Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applica
4 min read
Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter o
6 min read
Python | Simple calculator using Tkinter
Prerequisite : Tkinter IntroductionPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest
3 min read
Scientific GUI Calculator using Tkinter in Python
Prerequisite: Python GUI â tkinter In this article, we are going to create GUI Scientific Calculator using Python. As you can see, calculating large numbers nowadays is difficult or time-consuming. We've created a simple Scientific Calculator GUI using Python that allows you to perform simple and co
13 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Pyth
7 min read
Python | GUI Calendar using Tkinter
Prerequisites: Introduction to Tkinter Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will le
4 min read