0

I saw the answer to this question, and I wondered how does tkinter know which configurations should apply to what Frame?

The code that's used in the answer is the following:

import tkinter as tk

root = tk.Tk()
root.geometry("200x100")

f1 = tk.Frame(root, background="bisque", width=10, height=100)
f2 = tk.Frame(root, background="pink", width=10, height=100)

f1.grid(row=0, column=0, sticky="nsew")
f2.grid(row=0, column=1, sticky="nsew")

root.grid_columnconfigure(0, weight=0)
root.grid_columnconfigure(1, weight=1)

root.mainloop()

So I think my main question is how does tkinter know that the first grid.column_configure should apply to the first f1 = tk.Frame()?

Jem
  • 557
  • 9
  • 28
  • 2
    because it was referenced by 0. So column "0" contains "f1" and has the weight of 0. – Thingamabobs Jul 19 '20 at 11:29
  • 1
    see number `0` in `f1.grid(column=0, ...)` and `root.grid_columnconfigure(0, ...)` - it means the same column. Important is also `root` in both `f1 = tk.Frame(root,...)` and `root.grid_columnconfigure(0, ...)` – furas Jul 19 '20 at 12:27
  • Makes a lot of sense now, thanks for the answers! – Jem Jul 19 '20 at 12:49

1 Answers1

2

So I think my main question is how does tkinter know that the first grid.column_configure should apply to the first f1 = tk.Frame()?

It doesn't know that, because it doesn't apply to f1. Both calls to columnconfigure in your code applies to the root window. It knows this because that's the window it is called on (root.grid_columnconfigure...))

If you wanted it to apply to f1, you would call f1.grid_columnconfigure....

It affects f1 because you're calling columnconfigure on column zero and f1 is in column zero.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685