'How can i change frame.pack() into a form of grid, so i can use grid throughout my program

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)


Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1