Nesting grids and frames in tkinter and python -


i'm trying set grid inside of frame in larger grid structure. i've tried distill simplest version of problem.

from tkinter import tk, frame, label, entry  root = tk() root.geometry('800x800')   frame1 = frame(root, width=400, height=400, background="blue") frame2 = frame(root, width=400, height=400, background="red")  frame1.grid(row=0, column=0) frame2.grid(row=1, column=1)  label1 = label(frame1,text='label1') label1.grid() 

instead of placing label inside of frame1, label replaces frame in overall grid:

sample output

i've looked @ other examples, haven't been able identify why work , mine not.

the width= , height= of frame apply when has no children. once child widgets added, resizes fit contents. frame1 still there, it's same size as, , entirely covered by, label.

to turn off auto-resizing behavior, call .grid_propagate(0) on frame (or .pack_propagate(0), depending on geometry manager being used frame's children).


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -