class images_ui():
def __init__(self, path):
self.lis_small_images = []
self.path = path
self.img_nums = len(self.path)
self.small_image_obj = []
self.big_image_obj = []
self.pil_image = None
self.small_image_label_list = []
self.current_index = 0
self.win = tk.Toplevel()
self.win.geometry('{}x{}'.format(1920, 1080))
self.create_ui_init()
self.win.mainloop()
def make_win_width_height(self):
img = Image.open(self.path[0])
width, height = img.size
return width, height
def f1(self, img_path):
'''
w_ : 要适应的窗口宽
h_ : 要适应的窗口高
'''
img = Image.open(img_path)
w_ = 608
h_ = 1080
w, h = img.size
if w < h:
f1 = 1.0 * w_ / w
f2 = 1.0 * h_ / h
factor = min([f1, f2])
width = int(w * factor)
height = int(h * factor)
return img.resize((width, height), Image.ANTIALIAS)
else:
return img
def clear_small_lis_view(self):
for index, _small_image_label in enumerate(self.small_image_label_list):
_small_image_label.destroy()
def update_small_lis_view(self):
pass
def select_small_img(self, index):
self.entire_image_label.config(image=self.big_image_obj[index])
self.clear_small_lis_view()
self.small_image_label_list = self.small_image_label_list[index + 1:]
self.update_small_lis_view()
def pre_org_img(self, index):
if len(self.path) - 1 >= index - 2 and index - 2 >= 0:
self.current_index -= 2
self.entire_image_label.config(image=self.big_image_obj[self.current_index])
self.frame_right.configure(
text=self.path[self.current_index] + "\t" + f"{self.current_index + 1}/{self.img_nums}")
else:
print("最后一张了")
return
def get_pre_border_img(self, index):
if len(self.path) - 1 >= index - 1 and index - 1 >= 0:
self.current_index -= 1
self.entire_image_label.config(image=self.big_image_obj[self.current_index])
self.frame_right.configure(
text=self.path[self.current_index] + "\t" + f"{self.current_index + 1}/{self.img_nums}")
else:
print("最后一张了")
return
def next_org_img(self, index):
if len(self.path) - 1 >= index + 2:
self.current_index += 2
self.entire_image_label.config(image=self.big_image_obj[self.current_index])
self.frame_right.configure(
text=self.path[self.current_index] + "\t" + f"{self.current_index + 1}/{self.img_nums}")
else:
print("最后一张了")
return
def get_next_border_img(self, index):
if len(self.path) - 1 >= index + 1:
self.current_index += 1
self.entire_image_label.config(image=self.big_image_obj[self.current_index])
self.frame_right.configure(
text=self.path[self.current_index] + "\t" + f"{self.current_index + 1}/{self.img_nums}")
else:
print("最后一张了")
return
def create_ui_init(self):
for small_img_path in self.path:
org_img = self.f1(small_img_path)
org_img_tp = ImageTk.PhotoImage(org_img)
self.big_image_obj.append(org_img_tp)
self.frame_right = tk.LabelFrame(self.win,
text=self.path[
self.current_index] + "\t" + f"{self.current_index + 1}/{self.img_nums}",
labelanchor="n")
self.frame_right.place(relx=0.04, rely=0.04, relwidth=0.9, relheight=0.9)
self.pre_org_img_button = tk.Button(self.win, text="上2张图",
command=lambda: self.pre_org_img(self.current_index))
self.pre_org_img_button.place(relx=0.95, rely=0.3, relwidth=0.04, relheight=0.05)
self.pre_border_img_button = tk.Button(self.win, text="上1张图",
command=lambda: self.get_pre_border_img(self.current_index))
self.pre_border_img_button.place(relx=0.95, rely=0.5, relwidth=0.04, relheight=0.05)
self.next_org_img_button = tk.Button(self.win, text="下2张图",
command=lambda: self.next_org_img(self.current_index))
self.next_org_img_button.place(relx=0.95, rely=0.4, relwidth=0.04, relheight=0.05)
self.next_border_img_button = tk.Button(self.win, text="下1张图",
command=lambda: self.get_next_border_img(self.current_index))
self.next_border_img_button.place(relx=0.95, rely=0.6, relwidth=0.04, relheight=0.05)
self.entire_image_label = tk.Label(self.frame_right, text="???", image=self.big_image_obj[0])
self.entire_image_label.pack()
|