From 4d164f8d4dd0258b0eb424f9639c980a21cd6042 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 7 May 2021 01:50:46 -0400 Subject: [PATCH] Scales on the fly as window size changes. Also have the width scaling to maintain aspect ratio --- main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 9981f2b..e987728 100644 --- a/main.py +++ b/main.py @@ -19,6 +19,7 @@ class MangaReader: master.geometry("700x900") master.resizable(width=True, height=True) + # Menu Bar self.menu = Menu(master) item = Menu(self.menu) @@ -49,6 +50,7 @@ class MangaReader: # display image self.panel = Label(self.master, image=self.img) self.panel.pack() + self.panel.bind('', self.redraw) def open_menu(self): # file dialog. reset page counts, call display Maanga passing in starting values @@ -78,11 +80,16 @@ class MangaReader: data = zip.read(fl[pg]) im = Image.open(io.BytesIO(data)) + # I found the below code to maintain image ratios at https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio + # wpercent = (basewidth / float(im.size[0])) # hsize = int((float(im.size[1]) * float(wpercent))) + #Modified above code to maintain height and scale width + hpercent = (hsize / float(im.size[1])) + widthsize = init((float(im.size[0] * float(hpercent)))) - im = im.resize((wsize, hsize), Image.ANTIALIAS) + im = im.resize((widthsize, hsize), Image.ANTIALIAS) #convert to tkImage and update the on screen image. self.img = ImageTk.PhotoImage(im) self.panel.config(image=self.img) @@ -107,7 +114,10 @@ class MangaReader: else: #reset self.page and doNothing self.page = self.page + 1 - + + def redraw(self, event): + if self.file != 'None': + self.displayManga(self.file, self.page) #initalize tk root=Tk()