0

I am trying to run the following code:

from tkinter import *
root = Tk()
topFrame = Frame(root)
topFrame.pack(side=TOP)
leftFrame = Frame(root)
leftFrame.pack(side=LEFT)
botFrame = Frame(root)
botFrame.pack(side=BOTTOM)
button1 = Button(leftFrame, text="Button 1", fg="Black")
button2 = Button(leftFrame, text="Button 2", fg="Black")
button3 = Button(leftFrame, text="Button 3", fg="Black")
button1.grid(row=0, column=0)
button2.grid(row=1, column=0)
button3.grid(row=2, column=0)
ScaleWidget = Scale(root, from_=0, to=100)
ScaleWidget.grid(row=0, column=1)
ScaleWidget = Scale(root, from_=0, to=100, orient=HORIZONTAL)
ScaleWidget.grid(row=0, column=1)
root.mainloop()

However I am getting to following error message:

D:\Python\python.exe D:/untitled/TkInter_Frame_Full_GUI.py
Traceback (most recent call last):
 File "D:/untitled/TkInter_Frame_Full_GUI.py", line 21, in <module>
 ScaleWidget.grid(row=0, column=1)
 File "D:\Python\lib\tkinter\__init__.py", line 2057, in grid_configure
 + self._options(cnf, kw))
_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack

and am unsure of what to do, help is much appreciated, thanks!

asked Jan 29, 2015 at 14:18
5
  • It is advised not to mix pack and grid Commented Jan 29, 2015 at 14:20
  • Try putting your Scale widgets inside one of your frames instead of putting them directly in the root. Commented Jan 29, 2015 at 14:27
  • 1
    @BhargavRao: be careful with that advice. A better way to say it is you absolutely cannot mix grid and pack in the same container, but you can (and it's encouraged) to use both grid and pack within an application as a whole. Commented Jan 29, 2015 at 15:07
  • @BryanOakley I'm sorry, I actually meant to say that... :( Commented Jan 29, 2015 at 15:08
  • Possible duplicate of Cannot use geometry manager pack inside Commented Feb 14, 2018 at 21:13

1 Answer 1

1

You shouldn't mix grid and pack managers for windows that share a common parent:

Warning: Never mix grid and pack in the same master window. Tkinter will happily spend the rest of your lifetime trying to negotiate a solution that both managers are happy with. Instead of waiting, kill the application, and take another look at your code. A common mistake is to use the wrong parent for some of the widgets.

Source : http://effbot.org/tkinterbook/grid.htm

Bryan Oakley
389k53 gold badges584 silver badges741 bronze badges
answered Jan 29, 2015 at 14:22
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.