create_image 명령은 이미지를 찾고 명령의 이미지 매개 변수로 전달하는 경로에 대한 오류를 표시합니다.
역 추적 (최근 호출 마지막) :
파일 "C : \ Users \ SAURAV DAS \ AppData \ Local \ Programs \ Python \ Python35 \ projects \ classify_gui.py", 29 행,
모듈 cv.create_image (0, 0, image =) photo, anchor = 'nw') AttributeError : 'NoneType'개체에 'create_image'속성이 없습니다.
이미지의 경로를 찾아서 표시 할 수있는 다른 방법이 있습니까?
또는
Windows 10에서 Python 3.5를 사용 하고있는 캔버스 개체에 이미지를 표시하는 방법을 변경합니다 . 코드에 언급 된 모든 필수 라이브러리를 설치했습니다. 내가 사용하는 모든 이미지는 내 프로젝트로 작업 디렉토리에 있습니다.
도와주세요...
import sys
import tkinter as tk
from PIL import Image,ImageTk,ImageFilter,ImageOps
global fname
fname = "images.png"
def browse_file():
fname = tk.filedialog.askopenfilename(filetypes=(("Bitmap files", "*.bmp"), ("JPEG files", "*.jpg"), ("PNG files", "*.png"), ("All files", "*")))
print(fname)
return
def classify_obj():
print("In Development")
return
root = tk.Tk()
root.wm_title("Classify Image")
broButton = tk.Button(master=root, text='Browse', height=2, width=8, command=browse_file).grid(row=0, column=0, padx=2, pady=2)
frame1 = tk.Frame(root, width=500, height=400, bd=2).grid(row=1, column=0)
im = Image.open(fname)
photo = ImageTk.PhotoImage(im)
cv = tk.Canvas(frame1, height=390, width=490, background="white", bd=1, relief=tk.RAISED).grid(row=1,column=0)
cv.create_image(0, 0, image=photo, anchor='nw')
claButton = tk.Button(master=root, text='Classify', height=2, width=10, command=classify_obj).grid(row=0, column=1, padx=2, pady=2)
frame2 = tk.Frame(root, width=500, height=400, bd=1).grid(row=1, column=1)
cv = tk.Canvas(frame2, height=390, width=490, bd=2, relief=tk.SUNKEN).grid(row=1,column=1)
tk.mainloop()
그리드 관리자의 메서드는 위젯을 반환하지 않습니다. 따라서 위젯 끝에 그리드 메서드를 배치하지 마십시오. 대신 위젯이 생성 된 후 그리드를 구성하십시오.
이것을 변경하십시오 :
cv = tk.Canvas(frame1, height=390, width=490, background="white", bd=1, relief=tk.RAISED).grid(row=1,column=0)
cv.create_image(0, 0, image=photo, anchor='nw')
이에:
cv = tk.Canvas(frame1, height=390, width=490, background="white", bd=1, relief=tk.RAISED)
cv.grid(row=1,column=0)
cv.create_image(0, 0, image=photo, anchor='nw')
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다