You must not forget to close the file once you have finished working with it with myFile.close() because it is only at that point where all the changes, updates, writings, are done.Īn small snippet for adding a line: f = open("/path/to/myFile.txt", 'a')į. We need three important widgets to create the desired text editor GUI with Python 2 button widgets to save and close, and a text box widget to create and edit text files. This is the argument you should use when adding lines to non empty files. In this article, I will walk you through how to create a text editor GUI with Python that can create, open, edit, and save text files. W stands for write and will not only erase everything the file had (if it existed), but let you write new stuff on it through myFile.write("stuff I want to write").Ī stands for append and will add content to an existing file without erasing what could have been written on it. R stands for read and will make the open("/path/to/myFile.txt", 'r') to open an existing file and to only be able to read it (not editing), with myFile.readlines() or other methods you can find in this documentation. I hope this tutorial was helpful to you, thank you ‘Keep Learning Keep Coding’. You have three principal modes (the most used): r, w and a. Run the text editor file: Click on the file menu and select open command: Select the file you want to open: Click on open Button: Now you can enjoy editing your file: So In this way, you can create a simple text editor using Python and Tkinter library. The open() built-in Python method ( doc) uses normally two arguments: the file path and the mode.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |