Я попробовал этот код, чтобы отобразить изображение на холсте, используя open1
вызов fuction .... возможно ли это сделать .... как каждый раз, когда я пытался, он показывает указанные ниже ошибки
Ошибки
"C:\Program Files (x86)\Python37-32\python.exe" C:/Users/suhel/PycharmProjects/steography.py/main.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/suhel/PycharmProjects/steography.py/main.py", line 16, in open1
photo=PhotoImage(file=img)
File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 3545, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 3501, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "<_io.TextIOWrapper name='C:/Users/suhel/PycharmProjects/steography.py/rotated.png' mode='r' encoding='cp1252'>":
no such file or directory
Это мой код
from tkinter import *
from tkinter.font import *
from tkinter import filedialog
from tkinter import messagebox
from PIL import ImageTk
import cv2
import tkinter
from PIL import Image
from PIL import ImageTk
# **this is open fuction that allow to open a windows and
# select an image,i have tried to used used Canvas to display the image
# in the window,but it only display an empty window**
def open1():
img=filedialog.askopenfile(initialdir="/",title="select file",filetypes=(("image files",".png"),("all files","*py")))
r1=Tk()
canvas=Canvas(width=400,bg='blue')
photo=PhotoImage(file=img)
canvas.create_image(0,0,image=photo,anchor=NW)
canvas.pack()
r1.mainloop()
#main window
root=Tk()
#string var
ans1=StringVar
root.title(" Steganography")
label=Label(root,text="Image Based Steganography",anchor="center",fg="#7cd36b",bg="#000000")
label.pack()
f=Font(label,label.cget("font"))
f.config(family="Helvetica",size=15,weight="bold",underline=True)
label.configure(font=f)
entry=Entry(root,font=("Helvetica 16 bold italic"),insertwidth=4,width=50,textvariable=ans1)
entry.pack(padx=20, pady=20)
top=Frame(root)
choose=Button(top,text="Open",fg="#7cd36b",width=13,font=("Helvetica 10 bold italic"),bd=5,command=open1)
choose.grid(row=1,column=0,padx=6,pady=5)
get=Button(top,text="get",fg="#7cd36b",width=13,font=("Helvetica 10 bold italic"),bd=5)#,command=lambda:option())
get.grid(row=1,column=2)
top.configure(background="#000000")
top.pack()
root.configure(background="#000000")
root.geometry("350x400+400+400")
root.mainloop()