Помогите с изображением! AttributeError: type object 'Image' has no attribute 'open'
Виктор Алёшин
Знаток
(451),
на голосовании
5 лет назад
from tkinter import * from PIL import Image from tkinter.filedialog import * from tkinter.messagebox import * import fileinput
sa = None
def _open(): global sa sa = askopenfilename() print(sa) f = open(sa, "r", encoding='utf-8') content = f.read() txt.delete(1.0, END) txt.insert(END, content)
def _save(): global sa global content content = txt.get(1.0, END) f = open(sa, "w", encoding='utf-8') f.write(content) f.close()
def _exit(): global sa if askyesno("Exit", "Saved changes?"): if sa is None: sa = asksaveasfilename(defaultextension=".txt", filetypes=(("text file", "*.txt"), ("All Files", "*.*"))) _save() root.destroy()
from PIL import Image
from tkinter.filedialog import *
from tkinter.messagebox import *
import fileinput
sa = None
def _open():
global sa
sa = askopenfilename()
print(sa)
f = open(sa, "r", encoding='utf-8')
content = f.read()
txt.delete(1.0, END)
txt.insert(END, content)
def _save():
global sa
global content
content = txt.get(1.0, END)
f = open(sa, "w", encoding='utf-8')
f.write(content)
f.close()
def _about():
win = Toplevel(root)
win.iconbitmap('First_String.ico')
win.geometry('300x200')
lab = Label(win, text="First string version 1.4\n"
"Developer:NewModernSoft\n"
"2019.02.16\n"
"Copyrighted by NewModernSoft©")
lab.pack()
img = Image.open("mnm.png")
img.show()
def _exit():
global sa
if askyesno("Exit", "Saved changes?"):
if sa is None:
sa = asksaveasfilename(defaultextension=".txt", filetypes=(("text file", "*.txt"), ("All Files", "*.*")))
_save()
root.destroy()
def _newwindow():
root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
root.geometry("1000x800")
root.iconbitmap('First_String.ico')
root.title("First String")
m = Menu(root)
root.config(menu=m)
fm = Menu(m)
m.add_cascade(label="File", menu=fm)
fm.add_command(label="New", command=_newwindow)
fm.add_command(label="Open", command=_open)
fm.add_command(label="Save", command=_save)
hm = Menu(m)
m.add_cascade(label="Help", menu=hm)
hm.add_command(label="About Program", command=_about)
hm.add_command(label="Exit", command=_exit)
txt = Text(root, width=110, height=500, font='14', yscrollcommand=scrollbar.set)
txt.pack(side=LEFT, fill=BOTH)
scrollbar.config(command=txt.yview)
scrollbar.bind('')
root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
root.geometry("1000x800")
root.iconbitmap('First_String.ico')
root.title("First String")
m = Menu(root)
root.config(menu=m)
fm = Menu(m)
m.add_cascade(label="File", menu=fm)
fm.add_command(label="New", command=_newwindow)
fm.add_command(label="Open", command=_open)
fm.add_command(label="Save", command=_save)
hm = Menu(m)
m.add_cascade(label="Help", menu=hm)
hm.add_command(label="About Program", command=_about)
hm.add_command(label="Exit", command=_exit)
txt = Text(root, width=110, height=500, font='14', yscrollcommand=scrollbar.set)
txt.pack(side=LEFT, fill=BOTH)
scrollbar.config(command=txt.yview)
scrollbar.bind('')
root.mainloop()