Top = (screenHeight / 2) - (self._thisHeight /2) Left = (screenWidth / 2) - (self._thisWidth / 2) ScreenHeight = self._root.winfo_screenheight() ScreenWidth = self._root.winfo_screenwidth() # 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 \n Copyright \n with BSD license you can use it'") 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
0 Comments
Leave a Reply. |