Because it’s on top, the vertical padding offsets the button down from the top of the window a bit and makes sure that there’s a small gap between this and btn_save. You place 5 pixels of padding around each button just by setting the padx and pady parameters to 5. It makes sure both buttons are of the same size. The btn_open and btn_save both have their sticky attributes set to "ew", which forces the buttons to expand horizontally in both directions and in order to fill the entire frame.
btn_open is put in the first row and btn_save will be in the second row so that btn_open appears above btn_save in the layout, as planned in the above sketch.
#SETTINGS NEEDED ON A PYTHON TEXT EDITOR CODE#
The above two lines of code will create a grid with two rows and one column in the fr_buttons frame since both btn_open and btn_save have their master attribute set to fr_buttons. By configuring the second column, the text box will expand and contract naturally when the window is resized, while the column containing the buttons will always remain at a fixed width.ītn_id(row=0, column=0, sticky="ew", padx=5, pady=5)ītn_id(row=1, column=0, sticky="ew", padx=5) Keep it in mind that, row and column indices are zero-based, so these settings apply only to the second column. columnconfigure() to set the width and weight attributes of the column with index 1 to 900 and 1, respectively. Then take a look at this line in the code :
There’s only one row in the application layout, so these settings are applied to the entire window. rowconfigure() is set to 900 and weight is set to 1.The first argument is 0, which is used to set the height of the first row to 900 pixels and makes sure that the height of the row grows proportionally to the height of the window. The above-given line in the code indicates The minsize parameter of. Then the lines from 9 to 12 will create the four widgets you’ll need for the text box, the frame, and the open and save buttons. The next two lines of code are used to set the row and column configurations. Then the next two lines are used to create a new window with the title "Text Editor Application". The first command is used to import the tkinter. lumnconfigure(1, minsize=900, weight=1)ītn_open = tk.Button(fr_buttons, text="Open")ītn_save = tk.Button(fr_buttons, text="Save As.")
Window.rowconfigure(0, minsize=900, weight=1) The code snippet that is used is as follows: grid() as it is easier to work with it.Īs you can see in the output, we have a basic text editor application in which we can write something and then save the text in a new file or use the Open button to open a file in the editor and then edit it. According to the above-shown sketch, the two buttons should be stacked vertically inside of this frame, having btn_open on top. If you want both the buttons in the same column then you’ll need to create a Frame widget called fr_buttons. In order to handle the resizing, the weight parameters of these methods will be set to 1. In order to set the minimum sizes for the window and txt_edit, you just need to set the minsize parameters of the window methods. On the right side, there is A wider column for the text box On the left side, there is A narrow column for the buttons And this layout contains a single row and two columns: The desired layout of the Text Editor Application can be achieved using the. The width of the Frame that holds the buttons should not change. And The whole layout should be responsive if the window is resized, then txt_edit is resized as well. The Minimum height of the whole window should be 900 pixels and txt_edit should have a minimum width of 900 pixels. The arrangement of three widgets is done in a way such that the two buttons are on the left-hand side of the window, and the text box is on the right-hand side. Third, there is a Text widget called txt_edit for creating and editing any text file. Second one is a Button widget called btn_save for saving a file There is a Button widget called btn_open that is used for opening a file for editing In this tutorial, we will build a Text Editor Application from scratch.Įssential Elements for the Text editor application are as follows: Text Editor Application is an application where you can write your text, open any text file, you can edit any text file and you can also save a file if you want. Here, I will help you to build a simple Text Editor Application using Tkinter which is a very good beginner project for Tkinter.