Scales on the fly as window size changes. Also have the width scaling to maintain aspect ratio
This commit is contained in:
12
main.py
12
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('<Configure>', 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)
|
||||
@@ -108,6 +115,9 @@ class MangaReader:
|
||||
#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()
|
||||
|
||||
Reference in New Issue
Block a user