Cannot use geometry manager pack inside
Per the docs, don't mix pack
and grid
in the same master window:
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.
Thus, if you call grid
on the textbox, do not call pack
on the scrollbar.
import Tkinter as tk
import ttk
class App(object):
def __init__(self, master, **kwargs):
self.master = master
self.create_text()
def create_text(self):
self.textbox = tk.Text(self.master, height = 10, width = 79, wrap = 'word')
vertscroll = ttk.Scrollbar(self.master)
vertscroll.config(command=self.textbox.yview)
self.textbox.config(yscrollcommand=vertscroll.set)
self.textbox.grid(column=0, row=0)
vertscroll.grid(column=1, row=0, sticky='NS')
root = tk.Tk()
app = App(root)
root.mainloop()
cannot use geometry manager pack inside . which already has slaves managed by grid, although master windows are different
As @Bryan Oakley pointed out in the comment, using grid()
returns None
. So to fix it I had to separate instructions:
frame1 = LabelFrame(root, text="Frame1")
frame2 = LabelFrame(root, text="Frame2")
frame1.grid(row=0, column=0)
frame2.grid(row=0, column=1)
Python, cannot use geometry manager pack inside
This error can occur if you mix pack()
and grid()
in the same master window. According the docs, it is a bad idea:
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.
For example, this code is working for Python 3.3.x, but isn't working on Python 3.4.x (throws the error you mentioned):
from tkinter import *
from tkinter import ttk
root = Tk()
mainframe = ttk.Frame(root)
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
nb = ttk.Notebook(root)
nb.pack()
root.mainloop()
And this code isn't working for both Python versions:
from tkinter import *
root = Tk()
Label(root, text="First").grid(row=0)
Label(root, text="Second").pack()
root.mainloop()
To avoid this, use only one geometry manager for all children of a given parent, such as grid()
.
Error cannot use geometry manager pack inside . which already has slaves managed by grid
In your flagOpener()
function:
def flagOpener():
global flagIMG
global flagLabel
flagPath = filedialog.askopenfilename(initialdir="/", title="Select an Image File", filetypes=(("Png Files", "*.png"), ("Jpeg Files", "*.jpg; *.jpeg"), ("All Files", "*.*")))
flagIMG = ImageTk.PhotoImage(Image.open(flagPath))
flagLabel = Label(image=flagIMG)
flagLabel.pack()
return flagIMG, flagLabel
You didn't specify a parent for the flagLabel
. Tkinter used the default option for master which is root
but you used the grid
manager for root here:
def frameMaker():
frameName = Frame(root)
frameName.grid(row=0,column=0,sticky='nsew')
return frameName
and here:
titleframe = frameMaker()
politicalframe = frameMaker()
econframe = frameMaker()
miscframe = frameMaker()
for frame in (titleframe, politicalframe, econframe, miscframe):
frame.grid(row=0,column=0,sticky='nsew')
Tkinter doesn't allow you to use different managers for the same frame/window. Also why do you call the .grid
method twice for: (titleframe, politicalframe, econframe, miscframe)
? Once in the frameMaker
function then again the the for loop. You shouldn't do that.
Tkintter error: cannot use geometry manager grid inside . which already has slaves managed by pack
You cannot mix pack()
and grid()
from the docs:
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.
you are calling canvas.pack()
but to the same tk
object you add a button
on which you call the grid()
function.
Cannot use geometry manager grid inside - Need to use .grid() and not .pack()
As mentioned in the comments, you have to place every widget inside the frame, so you have to pass in self
as the parent of EVERY widget. You did not pass in self
for the Label
and hence the error.
def MyDir(self):
self.work_dir = askdirectory(title = 'Select Working Directory Folder')
myLabel = Label(self,text = self.work_dir) # Use self
myLabel.grid(row = 0, column = 1)
Or the other solution is to remove self.pack()
and use self.grid(row=0,column=0)
instead.
Not using grid anywhere still gives error 'cannot use geometry manager pack inside .frame2 which already has slaves managed by grid' in tkinter
Since you use pandas
dataframe, Table()
should be pandastable.Table
class which uses grid()
to layout its components inside its parent (in your case, it is analysisframe
). That is why you get the error because you use pack()
on other widgets in the same frame.
Use another frame for the pandastable.Table
and use pack()
on that frame:
def show_analysis():
# create a frame for the pandastable.Table
tableframe = Frame(analysisframe)
tableframe.pack()
# use tableframe as the parent
pt = Table(tableframe, dataframe=analysis, width=1200, height=100,
editable=False, showtoolbar=True, showstatusbar=True)
pt.show()
Related Topics
Pandas: Convert Dtype 'Object' to Int
Pandas Unique Values Multiple Columns
Use Aws Glue Python with Numpy and Pandas Python Packages
Printing Without Newline (Print 'A',) Prints a Space, How to Remove
How to Run Function in a Subprocess Without Threading or Writing a Separate File/Script
Accessing CPU Temperature in Python
How to Call Python Code from C Code
Preprocessing in Scikit Learn - Single Sample - Depreciation Warning
Removing Entries from a Dictionary Based on Values
Use of True, False, and None as Return Values in Python Functions
Python Django Global Variables
Finding First and Last Index of Some Value in a List in Python
Iso to Datetime Object: 'Z' Is a Bad Directive
How to Get a Single Result from a SQL Query in Python
Downloading a Directory Tree with Ftplib
How to Get All Combinations of Length N in Python
Why Apply Sometimes Isn't Faster Than For-Loop in a Pandas Dataframe