1

I wrote this simple code using grid(), but there seem to be a problem and shows the error :

class Input_screen:

    def __init__(self,master):
        frame = Frame(master)
        frame.pack()

        self.name_lable = Label(frame,text = 'NAME')
        self.name_e = Entry(root)

        self.name_lable.grid(row=1,column=0,sticky=W)
        self.name_e.grid(row=1,column=1)    

root = Tk()
b = Input_screen(root)
root.mainloop()

TclError: cannot use geometry manager grid inside . which already has slaves managed by pack

DarkKing Ace
  • 11
  • 1
  • 2
  • 3
    You probably meant for the Entry to be a child of `frame`, rather that `root`. – jasonharper Sep 24 '19 at 19:40
  • Possible duplicate of [Cannot use geometry manager pack inside](https://stackoverflow.com/questions/23584325/cannot-use-geometry-manager-pack-inside) – schlenk Sep 24 '19 at 20:11
  • @jasonharper is probably right about the code fix. The question itself is probably a duplicate of https://stackoverflow.com/questions/23584325/cannot-use-geometry-manager-pack-inside?rq=1 which makes the same error just the other way round. – schlenk Sep 24 '19 at 20:13

1 Answers1

1

The error is telling you exactly what is wrong: you can't use both pack and grid with widgets that share a common parent. In this case, the common parent is "." which is the internal name for the root widget.

You're using pack for frame and grid for self.name_e, and both of those have the root window as their parent. You either need to use grid for both or pack for both.

Bryan Oakley
  • 341,422
  • 46
  • 489
  • 636