In this Python tkinter tutorial, how to make notepad by using Python Tkinter and we will also cover the different examples related to the Python tkinter. Besides this, we will also cover the whole code related to How to make notepad by using python tkinter.
How to Make Notepad by Using Python Tkinter
Notepad is used as a simple text editor it can build and corrects the plain text documents. The notepad is also known as a sheet of a paper that are used for written the things.
Github Link
Check this code in Repository from Github and you can also fork this code.
Github User Name: PythonT-Point
Block of Code:
In this block of code we importing the tkinter library such as import tkinter, import os, from tkinter import *, import tkinter.messagebox import *, from tkinter.filedialog import *.
# How to make notepad by using Python Tkinter
import tkinter
import os
from tkinter import *
from tkinter.messagebox import *
from tkinter.filedialog import *
Block of Code:
In this block of code we are creating the window and also giving the width and height to the window and then creating the text area and menu bar and after that we are creating the menu bar .
root = Tk()
# default window width and height
width = 600
height = 400
textarea = Text(root)
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
editmenu = Menu(menubar, tearoff=0)
helpmenu = Menu(menubar, tearoff=0)
Block of Code:
In this block of code we are adding the scrollbar by using scrollbar() method and also defining the init function.
# To add scrollbar
scrollbar = Scrollbar(textarea)
file = None
def __init__(self,**kwargs):
# Set icon
try:
self.root.wm_iconbitmap("Notepad.ico")
except:
pass
Block of code:
In this block of code we will set the window size and then we will set the window text and after that we are creating the window and then we are making the text area resizeable and after that creating a feature of description of the notepad after that adjust Scrollbar automatically according to the content.
# Set window size
try:
self.width = kwargs['width']
except KeyError:
pass
try:
self.height = kwargs['height']
except KeyError:
pass
# Set the window text
self.root.title("Untitled - Notepad")
# Center the window
screenWidth = self.root.winfo_screenwidth()
screenHeight = self.root.winfo_screenheight()
# For left-align
left = (screenWidth / 2) - (self.width / 2)
# For right-align
top = (screenHeight / 2) - (self.height /2)
# For top and bottom
self.root.geometry('%dx%d+%d+%d' % (self.width,
self.height,
left, top))
# To make the textarea auto resizable
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(0, weight=1)
# Add controls (widget)
self.textarea.grid(sticky = N + E + S + W)
# To open new file
self.filemenu.add_command(label="New",
command=self.newfile)
# To open a already existing file
self.filemenu.add_command(label="Open",
command=self.openfile)
# To save current file
self.filemenu.add_command(label="Save",
command=self.savefile)
# To create a line in the dialog
self.filemenu.add_separator()
self.filemenu.add_command(label="Exit",
command=self.quitapplication)
self.menubar.add_cascade(label="File",
menu=self.filemenu)
# To give a feature of cut
self.editmenu.add_command(label="Cut",
command=self.cut)
# to give a feature of copy
self.editmenu.add_command(label="Copy",
command=self.copy)
# To give a feature of paste
self.editmenu.add_command(label="Paste",
command=self.paste)
# To give a feature of editing
self.menubar.add_cascade(label="Edit",
menu=self.editmenu)
# To create a feature of description of the notepad
self.helpmenu.add_command(label="About Notepad",
command=self.showabout)
self.menubar.add_cascade(label="Help",
menu=self.helpmenu)
self.root.config(menu=self.menubar)
self.scrollbar.pack(side=RIGHT,fill=Y)
# Scrollbar will adjust automatically according to the content
self.scrollbar.config(command=self.textarea.yview)
self.textarea.config(yscrollcommand=self.scrollbar.set)
Block of code:
In this block of code we will defining the quit application and then defining the show about after that defining the open file.
def quitapplication(self):
self.root.destroy()
# exit()
def showabout(self):
showinfo("Notepad","Mrinal Verma")
def openfile(self):
self.file = askopenfilename(defaultextension=".txt",
filetypes=[("All Files","*.*"),
("Text Documents","*.txt")])
if self.file == "":
# no file to open
self.file = None
else:
# Try to open the file
# set the window title
self.root.title(os.path.basename(self.file) + " - Notepad")
self.textarea.delete(1.0,END)
file = open(self.file,"r")
self.textarea.insert(1.0,file.read())
file.close()
Block of code:
In this block of code we will defining the new file function and then we will defining the save file function and after that defining cut, copy, paste, and run function.
def newfile(self):
self.root.title("Untitled - Notepad")
self.file = None
self.textarea.delete(1.0,END)
def savefile(self):
if self.file == None:
# Save as new file
self.file = asksaveasfilename(initialfile='Untitled.txt',
defaultextension=".txt",
filetypes=[("All Files","*.*"),
("Text Documents","*.txt")])
if self.file == "":
self.file = None
else:
# Try to save the file
file = open(self.file,"w")
file.write(self.textarea.get(1.0,END))
file.close()
# Change the window title
self.root.title(os.path.basename(self.file) + " - Notepad")
else:
file = open(self.file,"w")
file.write(self.textarea.get(1.0,END))
file.close()
def cut(self):
self.textarea.event_generate("<<Cut>>")
def copy(self):
self.textarea.event_generate("<<Copy>>")
def paste(self):
self.textarea.event_generate("<<Paste>>")
def run(self):
# Run main application
self.root.mainloop()
# Run main application
notepad = Notepad(width=600,height=400)
notepad.run()
Code:
Hereafter splitting the code and explaining how to make Notepad by using in Python Tkinter, now we will see how the output look like after running the whole code.
# How to make notepad by using Python Tkinter
# How to make notepad by using Python Tkinter
import tkinter
import os
from tkinter import *
from tkinter.messagebox import *
from tkinter.filedialog import *
class Notepad:
root = Tk()
# default window width and height
width = 600
height = 400
textarea = Text(root)
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
editmenu = Menu(menubar, tearoff=0)
helpmenu = Menu(menubar, tearoff=0)
# To add scrollbar
scrollbar = Scrollbar(textarea)
file = None
def __init__(self,**kwargs):
# Set icon
try:
self.root.wm_iconbitmap("Notepad.ico")
except:
pass
# Set window size
try:
self.width = kwargs['width']
except KeyError:
pass
try:
self.height = kwargs['height']
except KeyError:
pass
# Set the window text
self.root.title("Untitled - Notepad")
# Center the window
screenWidth = self.root.winfo_screenwidth()
screenHeight = self.root.winfo_screenheight()
# For left-align
left = (screenWidth / 2) - (self.width / 2)
# For right-align
top = (screenHeight / 2) - (self.height /2)
# For top and bottom
self.root.geometry('%dx%d+%d+%d' % (self.width,
self.height,
left, top))
# To make the textarea auto resizable
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(0, weight=1)
# Add controls (widget)
self.textarea.grid(sticky = N + E + S + W)
# To open new file
self.filemenu.add_command(label="New",
command=self.newfile)
# To open a already existing file
self.filemenu.add_command(label="Open",
command=self.openfile)
# To save current file
self.filemenu.add_command(label="Save",
command=self.savefile)
# To create a line in the dialog
self.filemenu.add_separator()
self.filemenu.add_command(label="Exit",
command=self.quitapplication)
self.menubar.add_cascade(label="File",
menu=self.filemenu)
# To give a feature of cut
self.editmenu.add_command(label="Cut",
command=self.cut)
# to give a feature of copy
self.editmenu.add_command(label="Copy",
command=self.copy)
# To give a feature of paste
self.editmenu.add_command(label="Paste",
command=self.paste)
# To give a feature of editing
self.menubar.add_cascade(label="Edit",
menu=self.editmenu)
# To create a feature of description of the notepad
self.helpmenu.add_command(label="About Notepad",
command=self.showabout)
self.menubar.add_cascade(label="Help",
menu=self.helpmenu)
self.root.config(menu=self.menubar)
self.scrollbar.pack(side=RIGHT,fill=Y)
# Scrollbar will adjust automatically according to the content
self.scrollbar.config(command=self.textarea.yview)
self.textarea.config(yscrollcommand=self.scrollbar.set)
def quitapplication(self):
self.root.destroy()
# exit()
def showabout(self):
showinfo("Notepad","Mrinal Verma")
def openfile(self):
self.file = askopenfilename(defaultextension=".txt",
filetypes=[("All Files","*.*"),
("Text Documents","*.txt")])
if self.file == "":
# no file to open
self.file = None
else:
# Try to open the file
# set the window title
self.root.title(os.path.basename(self.file) + " - Notepad")
self.textarea.delete(1.0,END)
file = open(self.file,"r")
self.textarea.insert(1.0,file.read())
file.close()
def newfile(self):
self.root.title("Untitled - Notepad")
self.file = None
self.textarea.delete(1.0,END)
def savefile(self):
if self.file == None:
# Save as new file
self.file = asksaveasfilename(initialfile='Untitled.txt',
defaultextension=".txt",
filetypes=[("All Files","*.*"),
("Text Documents","*.txt")])
if self.file == "":
self.file = None
else:
# Try to save the file
file = open(self.file,"w")
file.write(self.textarea.get(1.0,END))
file.close()
# Change the window title
self.root.title(os.path.basename(self.file) + " - Notepad")
else:
file = open(self.file,"w")
file.write(self.textarea.get(1.0,END))
file.close()
def cut(self):
self.textarea.event_generate("<<Cut>>")
def copy(self):
self.textarea.event_generate("<<Copy>>")
def paste(self):
self.textarea.event_generate("<<Paste>>")
def run(self):
# Run main application
self.root.mainloop()
# Run main application
notepad = Notepad(width=600,height=400)
notepad.run()
Output:
After running the whole code we get the following output in which we can see that the notepad is created on the screen with the help of Python Tkinter on the screen.
So, in this tutorial, we have illustrated How to make notepad by using Python Tkinter. Moreover, we have also discussed the whole code used in this tutorial.
Read some more tutorials related to Python Turtle.
- Python Turtle Snake Game
- Python Turtle Chess Game
- How to Make a Dog Face Using Python Turtle
- How to Write Happy Birthday using Python Turtle
- How to Draw Netflix Logo in Python Turtle
I really like your writing style, wonderful info, thanks for putting up :D. “Kennedy cooked the soup that Johnson had to eat.” by Konrad Adenauer.
Wow wonderful blog layout How long have you been blogging for you make blogging look easy The overall look of your site is great as well as the content
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Wonderful beat I wish to apprentice while you amend your web site how could i subscribe for a blog web site The account aided me a acceptable deal I had been a little bit acquainted of this your broadcast provided bright clear idea
Yaşamkent diyetisyen, sağlıklı yaşam ve dengeli beslenme arayışında olan birçok kişi için önemli bir merkez haline gelmiştir.
Site fantástico Muitas informações úteis aqui estou enviando para alguns amigos e também compartilhando deliciosos E claro obrigado pelo seu esforço
Site fantástico Muitas informações úteis aqui, estou enviando para alguns amigos e também compartilhando deliciosas E, claro, obrigado pelo seu suor
Real Estate Great information shared.. really enjoyed reading this post thank you author for sharing this post .. appreciated
Viyana Teknik Üniversitesi, mühendislik, bilgi teknolojisi, doğa bilimleri ve daha birçok alanda sunduğu geniş kapsamlı programlarla dikkat çeker.
Techno rozen I really like reading through a post that can make men and women think. Also, thank you for allowing me to comment!
Mygreat learning naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
BaddieHub I am truly thankful to the owner of this web site who has shared this fantastic piece of writing at at this place.
Simplywall I very delighted to find this internet site on bing, just what I was searching for as well saved to fav
Normally I do not read article on blogs however I would like to say that this writeup very forced me to try and do so Your writing style has been amazed me Thanks quite great post
Simply Sseven I appreciate you sharing this blog post. Thanks Again. Cool.
Simply Sseven Good post! We will be linking to this particularly great post on our site. Keep up the great writing
Somebody essentially lend a hand to make significantly posts I might state That is the very first time I frequented your web page and up to now I surprised with the research you made to create this particular put up amazing Excellent job
Зарегистрируйтесь прямо сейчас и получите 100 фриспинов без депозита, чтобы испытать свою удачу в увлекательных играх и повысить свои шансы на крупный выигрыш. рейтинг казино онлайн qjfnqievws …
Hi, i think that i saw you visited my web site thus i came to ?eturn the favor텶’m attempting to find things to enhance my site!I suppose its ok to use a few of your ideas!!
Bu soba, içindeki yakıtın yanmasıyla oluşan ısıyı doğrudan çevresine yayar ve aynı zamanda suyun ısınmasını sağlar.
Pink Withney I just like the helpful information you provide in your articles
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Blue Techker Good post! We will be linking to this particularly great post on our site. Keep up the great writing
Blue Techker I very delighted to find this internet site on bing, just what I was searching for as well saved to fav
When searching for reliable legal services, Debsllcs.org/
stands out as a platform providing essential support for small businesses and individuals.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Magnificent beat I would like to apprentice while you amend your site how can i subscribe for a blog web site The account helped me a acceptable deal I had been a little bit acquainted of this your broadcast offered bright clear idea
I was recommended this website by my cousin I am not sure whether this post is written by him as nobody else know such detailed about my trouble You are amazing Thanks
Good way of explaining, and pleasant article to obtain information about my presentation topic, which i am going
to present in school.!
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Good day! Do you know if they make any plugins to
assist with SEO? I’m trying to get my website
to rank for some targeted keywords but I’m not seeing very
good results. If you know of any please share. Thanks!
I saw similar blog here: Eco blankets
Have three players stand outdoors the three-point line, one at the top and the other two at each facet.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
bulgaristan eğitim danışmanlığı alanında uzman ekiplerle sizlere hizmet vermektedir.
sugar defender official website
As a person that’s always been cautious regarding my blood sugar level, finding Sugar Defender
has been a relief. I really feel so much a lot more
in control, and my current check-ups have actually revealed positive renovations.
Understanding I have a reputable supplement to sustain my routine
gives me satisfaction. I’m so grateful for Sugar Protector’s influence on my health
and wellness!
You made some good points there. I looked on the net to find out more about the issue and found most individuals will go along with your views on this site.
Pretty! This has been an incredibly wonderful post. Thank you for supplying these details.
Your style is very unique in comparison to other folks I have read stuff from. Thank you for posting when you have the opportunity, Guess I’ll just book mark this blog.
I needed to thank you for this very good read!! I absolutely enjoyed every bit of it. I have got you book-marked to look at new things you post…
We have one merchandise you would call green expertise.
Way cool! Some extremely valid points! I appreciate you penning this post and the rest of the site is really good.
The typical price in the neighborhood is $5,146, which is larger than the common value of nursing properties in the area of $5,145.
Also included is a topical index, a directory of Christian organizations and ministries, a gospel overview, a daily Bible verse, and a weblog.
Stack up a number of stiff bangle bracelets together with a Rose Gold & Crystal Beringed Bracelet, giving any ensemble an intriguing contact.
BWER empowers businesses in Iraq with cutting-edge weighbridge systems, ensuring accurate load management, enhanced safety, and compliance with industry standards.
Not long ago i found your website and also have been reading along. I thought I might leave my initial comment. Nice blog. I’ll keep visiting this web site very frequently. Thank you
Mr Ring was born Jan 18, 1917, at Wilbur and remained there until his graduation from Wilbur High school .
Great web site you have here.. It’s difficult to find high-quality writing like yours these days. I truly appreciate individuals like you! Take care!!
I believe one of your ads caused my browser to resize, you might want to put that on your blacklist.
Thanks for another informative site. Where else could I get that type of information written in such an ideal way? I’ve a project that I am just now working on, and I have been on the look out for such information.
I always was interested in this subject and still am, appreciate it for posting .
i am a movie addict and i watch a lot of movie in just one night, the greatest movie for me is Somewhere In Tome~
The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my choice to learn, but I truly thought youd have one thing interesting to say. All I hear is a bunch of whining about one thing that you would repair in the event you werent too busy on the lookout for attention.
Sweet website , super design , very clean and utilise pleasant.
you can always count on toshiba laptops when it comes to durability, they are really built tough,
It is unusual for me to find something on the net thats as entertaining and fascinating as what youve got here. Your page is lovely, your graphics are great, and whats more, you use reference that are relevant to what you are talking about. You are certainly one in a million, man!
Only a few blogger would discuss this topic the way you do.,,’.,
Hello there, have you by chance thought about to publish regarding Nintendo or PS handheld?
I like what you guys are up also. Such intelligent work and reporting! Keep up the superb works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my web site
I hope you never stop! This is one of the best blogs Ive ever read. Youve got some mad skill here, man. I just hope that you dont lose your style because youre definitely one of the coolest bloggers out there. Please keep it up because the internet needs someone like you spreading the word.
This will be the proper weblog if you really wants to check out this topic. You are aware of much its virtually challenging to argue along with you (not too I just would want…HaHa). You certainly put a different spin on the topic thats been written about for a long time. Excellent stuff, just wonderful!
howdy, I am gettin my site ranked “lands end catalog”.
Excellent read, I simply passed this onto a colleague who has been conducting a little research on that. And the man actually bought me lunch because I discovered it for him smile So i want to rephrase that: Appreciate your lunch!
But a smiling visitor here to share the love (:, btw great style and design .
Really instructive and superb structure of articles, now that’s user friendly (:.
Very good blog post! Thought about valued all the looking at. I hope to find out alot more of your stuff. I presume you might fantastic information and furthermore prospect. I am just exceptionally satisfied utilizing this type of critical information.
Giamatti, while scenery chewing with the best, can graciously be referred to as giving a “cameo” in the film considering his very limited screen time.
Wow! This can be one particular of the most useful blogs We have ever arrive across on this subject. Actually Magnificent. I’m also a specialist in this topic therefore I can understand your hard work.
Hello, very helpful posting. My sister and I have recently been looking to find detailed facts on this subject type of stuff for a while, yet we could hardly until now. Do you think you can also make a few youtube video clips about this, I do think your webblog would be far more complete in case you did. In any other case, oh well. I am going to be checking out on this web-site within the not too distant future. E-mail me to maintain me up-to-date. granite countertops cleveland
This can be a enormous plus a highly intriguing e-mail have a look at on this excellent weblog.
Are you able to identify Bentley’s sportiest mannequin that prices up to $2 million for special edition fashions?
You produced some decent points there. I looked on the net for any issue and found most people goes as well as with the site.
When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I receive four emails with the exact same comment. Can there be in whatever way you possibly can remove me from that service? Thanks!
Excellent post, thank you a lot for sharing. Do you have an RSS feed I can subscribe to?
Hey, what kind of anti-spam plugin do you use for your blog.*;:*;
With havin so much content and articles do you ever run into any issues of plagorism or copyright violation? My site has a lot of exclusive content I’ve either created myself or outsourced but it looks like a lot of it is popping it up all over the web without my permission. Do you know any solutions to help protect against content from being ripped off? I’d certainly appreciate it.
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/en-IN/register?ref=UM6SMJM3
Your blog has the same post as another author but i like your better.”`,`
Empathetic for your monstrous inspect, in addition I’m just seriously good as an alternative to Zune, and consequently optimism them, together with the very good critical reviews some other players have documented, will let you determine whether it does not take right choice for you.
Thank you for the good critique. Me & my cousin were just preparing to do a little research about this. We got a book from our area library but I think I’ve learned more from this post. I’m very glad to see such fantastic info being shared freely out there..
I always was concerned in this subject and still am, thanks for putting up.
Exactly where maybe you have discovered the source meant for the following write-up? Great reading through I’ve subscribed to your blog feed.
Spot up for this write-up, I honestly think this fabulous website wants a lot more consideration. I’ll likely to end up again you just read a great deal more, thanks for that info.
I have read some good stuff here. Certainly worth bookmarking for revisiting. I wonder how much effort you put to create such a magnificent informative website.
Hey, nice art i add your blog to my rss!
what i like about cable internet is that it is almost immune to electrical noise which always degrades DSL lines.
This could be the appropriate blog for everyone who hopes to discover this topic. You understand much its virtually difficult to argue together with you (not that When i would want…HaHa). You certainly put a different spin on the topic thats been discussing for several years. Excellent stuff, just fantastic!
elton john can be only be the best singer and composer that i know. i like the song Candle In The Wind;
The bosses themselves were convincingly awful, especially the always-reliable Kevin Spacey as this sadistic, manipulative, and extremely cruel president of a company.