0
def createmat_window():
    mat = Toplevel(cal)
    frame1 = Frame(mat,bg='red',width=100,height=100).pack()
    choices = {'1', '2', '3', '4', '5'}
    pop = OptionMenu(frame1, opt1,*choices)
    pop.pack()
    opt1.set('1')



cal = Tk()                              # (ROOT_WINDOW )
cal.title("calculator")

opt1 = StringVar()
Matrix = Button(cal, padx=16, bd=8, fg="black", font=('arial', 15, 'bold'),
                    text="MAT", bg="honeydew3", command=createmat_window)
Matrix.grid(row=5, column=10)

it's giving me error _tkinter.TclError: cannot use geometry manager pack inside . which already has slaves managed by grid

but i have read that we can use different geometry managers in different windows irrespective of what other windows are using.

Enji
  • 83
  • 1
  • 10

1 Answers1

2

Because you do

frame1 = Frame(mat,bg='red',width=100,height=100).pack()

frame1 is assigned the value returned by pack(), which is None. (Also see this answer).

Now when you use frame1 as the master of the OptionMenu, this basically becomes

pop = OptionMenu(None, opt1,*choices)

Which makes the OptionMenu's master default to the main window, in this case cal, which already has a widget added with grid().

You should be good when you change the creation of the frame to

frame1 = Frame(mat,bg='red',width=100,height=100)
frame1.pack()
fhdrsdg
  • 10,297
  • 2
  • 41
  • 62
  • code runs fine, when i correct my frame pack line but now the frame background doesn't show red color and only the "option menu". What's the reason behind?? – Enji Jul 24 '18 at 19:20
  • Because the OptionMenu is exactly as large as the Frame it's in. If you want the Frame to be larger than the OptionMenu, you need to give additional arguments to the pack command like: `frame1.pack(expand=1, fill=BOTH)`. For more info about pack see [this effbot page](http://effbot.org/tkinterbook/pack.htm). – fhdrsdg Jul 25 '18 at 07:01