Content in Scrollable Frame is cut off
I am using the CTkScrollableFrame to display pages from a pdf. When I load in a pdf of more than 39 pages, it cuts off somewhere at the 39th page. When I load the same pdf into basically the same code, except that it's using regular tkinter, it doesn't cut off but shows the entire pdf. The CTkScrollableFrame seems to stack the last pages of the pdf partially on top of each other without displaying all of it. The scrollable frame itself is, however, bigger than where the last page of the pdf is displayed. So the size of the frame does not seem to be the issue. I would rather keep using the CTkScrollableFrame because it works a lot easier in my opinion.
See the pictures (picture 1 is the CTk version, picture 2 is the regular Tkinter version) as well as the pdf file attached. If you need anything else, let me know! Help is greatly appreciated.
Here is my CTk code. I tried to keep it as minimal as possible and it is all supossed to be in one file: `from tkinter import filedialog as fd import os import customtkinter as ctk import math import fitz from tkinter import PhotoImage
root = ctk.CTk()
class PDFViewer: def init(self, master): #Variables self.path = None self.fileisopen = None self.name = None self.numPages = None self.zoomdict = {800:1.8, 700:2.0, 600:2.3, 500:2.4, 400: 2.5}
#Creating the windows and frames
self.master = master
self.menu_frame = ctk.CTkFrame(self.master)
self.menu_frame.pack(side='top', fill='x', pady=5)
self.main_frame = ctk.CTkFrame(self.master)
self.main_frame.pack(expand=1, fill='both')
self.main_frame.grid_columnconfigure((0), weight=1)
self.main_frame.grid_rowconfigure(0, weight=1)
#Creating the frame for displaying the pdf
self.output = ctk.CTkScrollableFrame(self.main_frame)
self.output.grid(row=0, column=0, sticky='nsew', padx=5, pady=5)
self.output.grid_columnconfigure((0,2), weight=1)
#Creating the open file button
self.file_lbl = ctk.CTkButton(self.menu_frame, text='Open File', font=('Helvetica', 28, 'bold'), command=self.open_file)
self.file_lbl.pack(side='top', anchor='center')
#Function for opening the pdf file
def open_file(self):
filepath = fd.askopenfilename(title='Select a PDF file', initialdir=os.getcwd(), filetypes=(('PDF', '*.pdf'), ))
if filepath:
self.path = filepath
self.miner = PDFMiner(self.path)
numPages = self.miner.get_metadata()
if numPages:
self.numPages = numPages
self.fileisopen = True
self.display_pdf()
self.master.title(self.name)
#Function for displaying the pdf file
def display_pdf(self):
for pagenum in range(0, self.numPages):
self.img_file = self.miner.get_page(pagenum, self.zoomdict)
pdfpage = ctk.CTkLabel(self.output, text='', image=self.img_file)
pdfpage.grid(row=pagenum, column=1, pady=1)
class PDFMiner: def init(self, filepath): self.filepath = filepath self.pdf = fitz.open(self.filepath) self.first_page = self.pdf.load_page(0) self.width, self.height = self.first_page.rect.width, self.first_page.rect.height
def get_metadata(self):
numPages = self.pdf.page_count
return numPages
def get_page(self, page_num, zoomdict):
width = int(math.floor(self.width/100.0) * 100)
self.zoom = zoomdict[width]
page = self.pdf.load_page(page_num)
pix = page.get_pixmap()
px1 = fitz.Pixmap(pix, 0) if pix.alpha else pix
imgdata = px1.tobytes("ppm")
return PhotoImage(data=imgdata)
app = PDFViewer(root) root.mainloop()`
same issue here
@Omenta-T and @KorryKatti
This is because customtkinter uses a Frame object/window to display elements. Each time you add a new element, the frame gets expanded in height (if orientation = "vertical"). Windows operating system (also others) has a definite max window size! to save memory and security threads.
To fix this problem: it's really lengthy!
Use Canvas, and draw your images (using create_image() method or windows (using create_window() method) one by one.
Canvas provides easy scrolls for its shapes!
In mean time, I may post a fully supported sample code here, but before that you can try to implement this by your own.
Regards.