0

I guess I didn't quite understand how tk.Frame works, but I couldn't find a documentation that would help me understand what is happening:

I want to create a GUI with Tkinter and I want to use frames to distribute the available space to all its groups of elements. For simplicity, I want a label, below a frame containing two buttons and another frame with a progressbar.

import tkinter as tk 
from tkinter import ttk

window = tk.Tk()
window.geometry()
lbl_1 = tk.Label(master = window, text='One Ring').pack()

frm_A = tk.Frame(master=window).pack()
btn_2 = tk.Button(master=frm_A, text='rule them').pack()
btn_3 = tk.Button(master=frm_A, text='find them').pack()

frm_B = tk.Frame(master=window).pack()
pb_4 = ttk.Progressbar(
    master=frm_B, 
    orient= 'horizontal', 
    mode= 'determinate', 
    length= 300
).pack()
lbl_5 = tk.Label(master=frm_B, text='forever binding 0%').pack()

window.mainloop()

Which oviously packs all widgets under each other

Instead I want the two buttons to be next to each other rather than below each other, but if I change their pack commands to:

btn_2 = tk.Button(master=frm_A, text='rule them').pack(side=tk.LEFT)
btn_3 = tk.Button(master=frm_A, text='find them').pack(side=tk.RIGHT)

The buttons will instead be arranged on the sides of the label and the progress-bar-frame

BONUS

Adding to my confusion: I tried to give the frame set sizes and a background color to see where they actually are by adjusting frm_B:

frm_B = tk.Frame(master=window,bg = 'black', width=150, height=150).pack()

But instead it just packed a the frame without anything inside of it next to its supposed content

Magnus
  • 15
  • 4
  • hint: the value of `frm_A` and `frm_B` is not what you think it is. The first step in debugging should be to verify that your variables contain what you think they should contain. – Bryan Oakley Nov 03 '21 at 15:41
  • Does this answer your question? [Tkinter: AttributeError: NoneType object has no attribute ](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) The question is not exactly the same as yours but the answer will solve your issue. after you read that question and answers: Basically if you use `None` as the master it will use the `Tk` instance as the master – Matiiss Nov 03 '21 at 15:46
  • @Matiiss Yes, I found the relevant part and noticed the similarity, that really helped! Thanks a lot! – Magnus Nov 03 '21 at 15:53

0 Answers0