user16806547
user16806547

Reputation:

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

I want to use grid to show pdf but it's showing error that cannot use geometry manager pack inside . which already has slaves managed by grid.

from tkinter import *
from tkPDFViewer import tkPDFViewer as pdf

mys = Tk()
mys.title("Mystery Books")
mys.config(bg='white')

I changed to grid() from pack() inside dead function but still there's something I can't find out to change to grid overall.

def dead():

    root = Toplevel()

    root.geometry("550x750")
    v1 = pdf.ShowPdf()
    v2 = v1.pdf_view(root,pdf_location=r"C:\\Users\\mande\\Desktop\\Books\\Mystery\\Dead Until Dark.pdf")
    v2.grid()

    root.mainloop()

button_dead = Button(mys, text="Dead until Dark", font=30, padx=15, pady=15, height=2, width=12, command=dead,fg="black", bg="white", borderwidth=5)
button_dead.grid(row=1, column=0, padx=7, pady=7)

mys.mainloop()

Upvotes: 0

Views: 469

Answers (1)

acw1668
acw1668

Reputation: 46688

This is a bug of tkPDFViewer. Look into the code of tkPDFViewer:

class ShowPdf():
    ...
    def pdf_view(self,master,width=1200,height=600,pdf_location="",bar=True,load="after"):
        ...
        if bar==True and load=="after":
            self.display_msg = Label(textvariable=percentage_load) # this will create the label in root window instead of its frame
            self.display_msg.pack(pady=10) # this will raise exception if widgets in root window are using `grid()`
            ...

To skip the bug, pass bar=False or load="" when calling pdf_view(...):

v2 = v1.pdf_view(root,
                 pdf_location=r"C:\\Users\\mande\\Desktop\\Books\\Mystery\\Dead Until Dark.pdf",
                 bar=False) # set bar=False

Note that the above change will disable the progress bar.

Upvotes: 1

Related Questions