Vibhu Manikpuri
Vibhu Manikpuri

Reputation: 55

Not using grid anywhere still gives error 'cannot use geometry manager pack inside .frame2 which already has slaves managed by grid' in tkinter

I am creating this app which works completely and I want to display the output (a pandas dataframe in table and a few matplotlib graphs) with a little GUI with tkinter. Since tkinter doesn't allow grid and pack to work together, I replaced all widgets geometry manager from grid to pack. It worked fine when I ran the program for first time but since then it has been giving me following error:

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

root =  Tk()
root.title('Stocks Analysis')
root.geometry('3000x2400')

var = IntVar()
var.set("1")

imgframe = Frame(root)
imgframe.place(x=0,y=0,relheight=1,relwidth=1)

img = PhotoImage(file = "bgimage.png")
label = Label(imgframe, image = img)
label.place(x=0, y=0, relheight=1, relwidth=1)

#mainframe = Frame(root, bgcolor='antique white', height=1400, width=2100, bd=4)
#mainframe.place(relwidth=0.2, relheight=0.25)



analysisframe = Frame(root, bg='antique white', height=1400, width=2100, bd=4)
analysisframe.place(relwidth=0.2, relheight=0.25)


def q():
    root.quit()
    #root.destroy()


def show_analysis():

    pt = Table(analysisframe, dataframe=analysis, width=1200, height=100, 
          editable=False, showtoolbar=True, showstatusbar=True)
    pt.show()

anbutton = Button(analysisframe, text = "Show Analysis", command = show_analysis())
anbutton.pack()

#infoframe = Label(root, text = "Select from following to display Visual Analysis ", font = 40)
#infoframe.pack()

#Radiobuttons for choosing analysis:

R1 =  Radiobutton(analysisframe, text="Open/Close", variable=var, value=1,
              command=lambda:openclose()).pack()
R2 =  Radiobutton(analysisframe, text="High/Low", variable=var, value=2,
              command=lambda:highlow()).pack()
R3 =  Radiobutton(analysisframe, text="Volume", variable=var, value=3,
              command=lambda:vol()).pack()
R4 =  Radiobutton(analysisframe, text="Simple Moving Average", variable=var, value=4,
              command=lambda:sma()).pack()
R5 =  Radiobutton(analysisframe, text="Bollinger Bands", variable=var, value=5,
              command=lambda:bands()).pack()

quitbutton = Button(analysisframe, text = "QUIT", command = q())
quitbutton.pack()

root.mainloop()

root.destroy()

I even tried creating a new Frame but that doesn't work either

Upvotes: 0

Views: 267

Answers (1)

acw1668
acw1668

Reputation: 46678

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()

Upvotes: 1

Related Questions