각각 이미지를 개별적으로 표시하는 4 개의 프레임으로 분할 된 이미지 뷰어를 만들려고합니다.이 오류가 계속 발생합니다.
Traceback (most recent call last):
File "c:/Users/EM/Desktop/Scripts/gui/slideshow_model/slide_show_class.py", line 60, in <module>
slideshow_model = SlideshowModel(root)
File "c:/Users/EM/Desktop/Scripts/gui/slideshow_model/slide_show_class.py", line 22, in __init__
self.frame_1, width=self.grid_w, height=self.grid_height)
File "C:\Users\EM\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
File "C:\Users\EM\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
File "C:\Users\EM\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
[Previous line repeated 494 more times]
RecursionError: maximum recursion depth exceeded
내 수업은 다음과 같습니다.
import tkinter as tk
from PIL import ImageTk, Image
root = tk.Tk()
class SlideshowModel(tk.Tk, tk.Frame):
def __init__(self, master):
self.master = root
master.title('Basic Image Viewer')
root.iconbitmap('../img/favicon.ico')
root.state('zoomed')
s_w = int(root.winfo_screenwidth())
s_h = int(root.winfo_screenheight())
self.grid_w = s_w // 2
self.grid_h = s_h // 2
self.frame_1 = tk.Frame(master, height=self.grid_h,
width=self.grid_w, bd=0)
self.frame_1.grid(column=0, row=0)
self.canvas_1 = tk.Canvas(
self.frame_1, width=self.grid_w, height=self.grid_height)
#self.frame_2 = tk.Frame(master, height=self.grid_h,
width=self.grid_w, bd=0, bg="black")
#self.frame_2.grid(column=1, row=0)
#self.frame_3 = tk.Frame(master, height=self.grid_h,
width=self.grid_w, bd=0, bg="black")
#self.frame_3.grid(column=0, row=1)
#self.frame_4 = tk.Frame(master, height=self.grid_h,
width=self.grid_w, bd=0, bg="black")
#self.frame_4.grid(column=1, row=1)
# show image function
# should contain grid coordinates
# image dimensions calculator
# should return the image object
def resize_image(self, img_path):
image = Image.open(img_path)
w_coeff = image.width / self.grid_w
h_coeff = image.height / self.grid_h
w_coeff = 1 / w_coeff if w_coeff > 1 else w_coeff
h_coeff = 1 / h_coeff if h_coeff > 1 else h_coeff
# pick the smallest coeff to get the image as small
# as should be
coeff = min(w_coeff, h_coeff)
image = image.resize(
(int(image.width * coeff), int(image.height * coeff)), Image.ANTIALIAS)
return image
# this function should show returned image
# takes: image object, master frame
def show_image(self, resize_image, frame_x):
image = ImageTk.PhotoImage(resize_image)
# label = tk.Label(frame_x, image=image, bd=0)
self.canvas_1(image=image, anchor='nw')
slideshow_model = SlideshowModel(root)
img1 = slideshow_model.resize_image('../img/sample.jpg')
# img2 = slideshow_model.resize_image('../img/sample.jpg')
# img3 = slideshow_model.resize_image('../img/sample.jpg')
# img4 = slideshow_model.resize_image('../img/sample.jpg')
slideshow_model.show_image(img1, slideshow_model.frame_1)
# slideshow_model.show_image(img2, slideshow_model.frame_2)
# slideshow_model.show_image(img3, slideshow_model.frame_3)
# slideshow_model.show_image(img4, slideshow_model.frame_4)
root.mainloop()
예외를 해결할 때까지 첫 번째 프레임에 초점을 맞추기 위해 세 개의 다른 프레임을 주석 처리했습니다. 나는 비슷한 게시 된 스레드를 조사해 왔으며, 내가 수집 할 수있는 것은 root.mainloop()
함수가 두 번 이상 호출 되어 발생하는 원인입니다 . 무엇을 놓치고 있습니까?
SlideshowModel (tk.Tk, tk.Frame) 클래스에서 "tk.Tk"및 "tk.Frame"을 제거하면 어떻게됩니까? 또한 self.grid_height를 self.grid_h로 바꿔야합니다 (22 행).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다