I specified a width for a frame, then I grid a button in it asking for it to be the widest it can using
from tkinter import *
root = Tk()
frame = Frame(root, width=100, height=100, background="#ffffff")
frame.pack()
btn = Button(frame, text="Hello").grid(row=0, column=0, sticky="we")
root.mainloop()
but it actually doesn't occupy the whole length of the frame, the frame is not even white. If I comment the button line it works just fine though. Why is that?
CodePudding user response:
This is what the commentors were telling you to do. Tell your frame not to propagate to grid.
from tkinter import *
root = Tk()
frame = Frame(root, width=500, height=500, background="red")
frame.pack()
frame.grid_propagate(0) # this fixes the frame issue you are having
btn = Button(frame, text="Hello")
btn.grid(row=0, column=0, sticky="we")
root.mainloop()
CodePudding user response:
I can suppose that it because u place your button 'on' frame, not on root. Hopefully, this will fix your problem:
btn = Button(root, text="Hello").pack()#.grid(row=0, column=0, sticky="we")