How it works...

Note how we aligned the label, but not the textbox below it. We have to use the sticky property for all the controls we want to left-align. We can do that in a loop, using the winfo_children() and grid_configure(sticky='W') properties, as we did before in the recipe, Using padding to add space around widgets, in this chapter.

The winfo_children() function returns a list of all the children belonging to the parent. This enables us to loop through all the widgets and change their properties.

  • Using tkinter to force the naming to the left, right, top, or bottom is very similar to Java: West, East, North, and South, abbreviated to 'W' and so on. We can also use the following syntax: tk.W instead of 'W'. This requires having imported the tkinter module aliased as tk.
  • In a previous recipe, we combined both 'W' and 'E' to make our ScrolledText widget attach itself both to the left- and right-hand sides of its container, using 'WE'. We can add more combinations: 'NSE' will stretch our widget to the top, bottom, and right side. If we only have one widget in our form, for example, a button, we can make it fill in the entire frame by using all options: 'NSWE'. We can also use tuple syntax: sticky=(tk.N, tk.S, tk.W, tk.E).

Let's align the entry in column 0 to the left:

Now, both the label and the entry are aligned towards the West (left):

GUI_embed_frames_align_entry_west.py
In order to separate the influence that the length of our Labels in a Frame LabelFrame has on the rest of our GUI layout, we must not place this LabelFrame into the same LabelFrame as the other widgets but assign it directly to the main GUI form (win). We will do this in the later chapters.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.18.141