Scales on the fly as window size changes. Also have the width scaling to maintain aspect ratio
This commit is contained in:
14
main.py
14
main.py
@@ -19,6 +19,7 @@ class MangaReader:
|
|||||||
master.geometry("700x900")
|
master.geometry("700x900")
|
||||||
master.resizable(width=True, height=True)
|
master.resizable(width=True, height=True)
|
||||||
|
|
||||||
|
|
||||||
# Menu Bar
|
# Menu Bar
|
||||||
self.menu = Menu(master)
|
self.menu = Menu(master)
|
||||||
item = Menu(self.menu)
|
item = Menu(self.menu)
|
||||||
@@ -49,6 +50,7 @@ class MangaReader:
|
|||||||
# display image
|
# display image
|
||||||
self.panel = Label(self.master, image=self.img)
|
self.panel = Label(self.master, image=self.img)
|
||||||
self.panel.pack()
|
self.panel.pack()
|
||||||
|
self.panel.bind('<Configure>', self.redraw)
|
||||||
|
|
||||||
def open_menu(self):
|
def open_menu(self):
|
||||||
# file dialog. reset page counts, call display Maanga passing in starting values
|
# file dialog. reset page counts, call display Maanga passing in starting values
|
||||||
@@ -78,11 +80,16 @@ class MangaReader:
|
|||||||
data = zip.read(fl[pg])
|
data = zip.read(fl[pg])
|
||||||
im = Image.open(io.BytesIO(data))
|
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]))
|
# wpercent = (basewidth / float(im.size[0]))
|
||||||
# hsize = int((float(im.size[1]) * float(wpercent)))
|
# 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.
|
#convert to tkImage and update the on screen image.
|
||||||
self.img = ImageTk.PhotoImage(im)
|
self.img = ImageTk.PhotoImage(im)
|
||||||
self.panel.config(image=self.img)
|
self.panel.config(image=self.img)
|
||||||
@@ -107,7 +114,10 @@ class MangaReader:
|
|||||||
else:
|
else:
|
||||||
#reset self.page and doNothing
|
#reset self.page and doNothing
|
||||||
self.page = self.page + 1
|
self.page = self.page + 1
|
||||||
|
|
||||||
|
def redraw(self, event):
|
||||||
|
if self.file != 'None':
|
||||||
|
self.displayManga(self.file, self.page)
|
||||||
|
|
||||||
#initalize tk
|
#initalize tk
|
||||||
root=Tk()
|
root=Tk()
|
||||||
|
|||||||
Reference in New Issue
Block a user