
# Set window size as mentioned above (the default is 300x300) _thisScrollBar = Scrollbar(_thisTextArea) _thisCommandMenu = Menu(_thisMenuBar, tearoff=0) _thisHelpMenu = Menu(_thisMenuBar, tearoff=0) _thisEditMenu = Menu(_thisMenuBar, tearoff=0) _thisFileMenu = Menu(_thisMenuBar, tearoff=0) #To get the dialog box to open when required Now we have added the required package, add a menu item and the required functionality we’re going to see in this notepad-like text editor using tkinter library.īelow is the complete program to create a notepad text editor using tkinter − #Import os library Self._file = asksaveasfilename(initialfile='Untitled.txt', defaultextension=".txt", filetypes=)įile.write(self._thisTextArea.get(1.0,END)) Self._thisTextArea.insert(1.0,file.read()) Self._root.title(os.path.basename(self._file) + " - Notepad") Self._file = askopenfilename(defaultextension=".txt", filetypes=) Showinfo("Notepad", "Just Another TextPad Showinfo("About Notepad","Simple text editor like notepad using Python") Below the list of functionality, we going to add to this notepad (of course you can add many others too).īelow is the code to implement, above mentioned functionality − def _quitApplication(self): Now we have the menu items ready, now we are going to add functionality to each of the menu items. Self._thisMenuBar.add_cascade(label="Help", menu=self._thisHelpMenu) Adding functionality to each Menu item Self._thisMenuBar.add_cascade(label="Commands", menu=self._thisCommandMenu) Self._thisCommandMenu.add_command(label = "About Commands", command=self._showCommand) Self._thisHelpMenu.add_command(label="About Notepad", # To create a feature of description of the notepad Self._thisMenuBar.add_cascade(label="Edit", menu=self._thisEditMenu) Self._thisEditMenu.add_command(label="Paste", Self._thisEditMenu.add_command(label="Copy", Self._thisEditMenu.add_command(label="Cut", Self._thisMenuBar.add_cascade(label="File", menu=self._thisFileMenu) Self._thisFileMenu.add_command(label="Exit", Self._thisFileMenu.add_command(label="Save", Self._thisFileMenu.add_command(label="Open", Self._thisFileMenu.add_command(label="New", We are going to give these many menu-item & subitem by using below code − # To open new file Our commands menu item will have one subitem – About commands,Īnd our help menu will have one subitem- About notepad

Our edit menu item will have three sub-items- cut, copy & paste Our file menu item will have four sub-items- New, Open, Save & Exit. Our notepad will have four main menu items: File, Edit, Commands & Help.

Note: tkinter comes as a standard library with python 3.x. This notepad will have the menu where we can create new file, open existing file, save the file, editing, cut and paste, all functionality will there. Here, using tkinter we will develop a notepad like text editor. Tkinter is a GUI library from python from which we can create multiple GUI apps.
