私はpython 3で画像を再プログラムするプログラムでPILを使用しています。それは、file.gif
(整数として返される)のピクセル値を恒久的にループし、それぞれに10を加えます。その後、ファイルを保存して、tkinterラベルに書き込むために再オープンすることができます(残りはありますが、保存について知っておく必要があります)。PILを使用してpython 3で画像を保存するにはどうすればよいですか?
このコードを使用すると、イメージを開いてウィンドウに表示してからピクセル値を変更するプログラムがありますが、表示されるイメージは変わりません。
from tkinter import *
from PIL import Image
from PIL import Image, ImageTk
import time, sys
def col():
global count1,count,pix,x,root
count1+=1
print("("+str(count1)+")")
count=-1
for i in pix:
count+=1
#print(i)
i+=10
pix[count]=i
photo = PhotoImage(file="AI.gif")
x.configure(image=photo)
root.update()
root.after(100, col)
root=Tk()
photo = PhotoImage(file="AI.gif")
x=Label(root, compound="top", image=photo)
x.pack(side="right")
img = Image.open("AI.gif")
pix=list(img.getdata())
width=img.size[0]
height=img.size[1]
img.close()
root.geometry((str(width)+"x"+str(height))+"-0+0")
root.update()
count1=0
col()
root.mainloop()
編集: @Tadhgマクドナルド・ジェンセン を私はすべてのあなたの提案編集してプログラムを実行してきましたが、このエラーを持っています:
Traceback (most recent call last):
File "C:\Users\name\Desktop\recolour1.py", line 47, in <module>
col()
File "C:\Users\name\Desktop\recolour1.py", line 19, in col
photo.paste(img)
AttributeError: 'PhotoImage' object has no attribute 'paste'
EDIT2:ここ は私です
from tkinter import *
from PIL import Image
from PIL import Image, ImageTk
import time, sys
def col():
global count1,count,pix,x,root,photo
img = Image.open("AI.gif").convert("RGB")
pix=list(img.getdata())
count1+=1
print("("+str(count1)+")")
count=-1
for i in pix:
count+=1
#print(i)
i = tuple(V+100 for V in i)
img.putdata(pix)
photo.paste(img)
root.update()
img.close()
root.after(10, col)
root=Tk()
photo = ImageTk.PhotoImage(file="AI.gif")
x=Label(root, compound="top", image=photo)
x.pack(side="right")
img = Image.open("AI.gif").convert("RGB")
width,height=img.size[0],img.size[1]
img.close()
root.geometry((str(width)+"x"+str(height))+"-0+0")
root.update()
count1=0
col()
root.mainloop()
:ちょうどすべての私の提案の編集とあなたのコードがあり、ここで明確にしますか? –
どうすればいいですか?私はまだ私が比較的新しいtkinterに言及するのを忘れた – sonrad10
あなたは自分自身に新しいものとして自分自身をラベル付けする必要はない(あなたの担当者がそれを示唆するのを助ける)私は喜んで答えを投稿するだろう... –