0

I keep getting the error message of "cannot use geometry manager grid inside . which already has slaves managed by pack" - which means i cant use pack and grid together. I dont know how to change frame.pack() into a form where i can use grid.

def __init__(self, master):

    frame = Frame(master)
    frame.pack()

    root.geometry("800x600")
    root.title("www.heathhighschool.co.uk/local/secure/management%system")
    root.iconbitmap("HeathIcon.ico")
   
    username = Label(frame, text="Username:").grid(row=1, column=0)
    username_entry = Entry().grid(row=1, column=1)
    
    passw = Label(frame, text="Password:").grid(row=2, column=0)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
shash
  • 1
  • _"which means i cant use pack and grid together."_ - just to be clear, you can use them both in an application, you just can't use them both for widgets that have the same parent. It's quite normal, if not an actual best practice, to use both in medium to large UIs. – Bryan Oakley Mar 18 '22 at 21:19
  • I would suggest that you shouldn't call `frame.pack()` in this code, as it means that this code needs to know how it's parent is managing other widgets. The code that creates this object should be responsible for calling `grid` or `pack` or whatever else it wants. – Bryan Oakley Mar 18 '22 at 21:24

1 Answers1

0

Entry().grid(row=1, column=1) Entry has no positional argument, such as root or frame which determinates the master and if no positional argument is given tk.Tk() (root) is set by default.

To solve your issue, either use a different master for your Entry or use frame.grid()


Also note that you can have in each master a nested layout, within you can choose to use .pack() or .grid().

See my answer here for a basic knowledge of tkinters geometry management.


In addition, your assignment will become None since .grid() returns None, while you want to keep a reference that is returned by Widget():

username = Label(frame, text="Username:")
username.grid(row=1, column=0)
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54