英文:
Tkinter how to insert image using Pillow
问题
CHONE_2Sc = tk.Tk()
FstAlien = ImageTk.PhotoImage(Image.open("alien.jpg"))
FstAlLabel = tk.Label(image=FstAlien)
FstAlien.show(command="display")
FstAlien.pack()
CHONE_2Sc.configure(background="lime")
CHONE_2Sc.title("ROCK,PAPERS,SCISSORS")
Object = tk.Entry()
Object.grid(row=100, column=100)
Object.insert(0, "Enter your object: ")
Object.get()
在Stack Overflow上查看已有的问题以确定你的问题是否是重复的。有一篇帖子说,如果你在Mac上使用,.open会显示图像。在Unix上,可以使用display、fim和其他一些工具来显示。但在Windows上,他没有具体说明,或者我没有理解得太清楚。
英文:
CHONE_2Sc = tk.Tk()
FstAlien = ImageTk.PhotoImage(Image.open("alien.jpg"))
FstAlLabel = tk.Label(image=FstAlien)
FstAlien.show(command= "display")
FstAlien.pack()
CHONE_2Sc. configure(background="lime")
CHONE_2Sc.title("ROCK,PAPERS,SCISSORS")
Object = tk.Entry()
Object.grid(row=100, column=100)
Object.insert(0, "Enter your object: ")
Object.get()
In the review questions already on Stack Overflow to see if your question is a duplicate. There was a post that said that if you're using Mac, .open will show the image. On unix, display, fim and something else would do it. But on windows he didn't specify that much or I didn't understand that much.
答案1
得分: 0
欢迎,Abdullah。您需要打包您的标签(FstAlLabel
),而不是您的图像对象(FstAlien
)。以下是一种方法。
FstAlien = ImageTk.PhotoImage(Image.open("alien.jpg"))
FstAlLabel = tk.Label(CHONE_2Sc, image=FstAlien)
FstAlLabel.pack()
如果这不起作用,请在最后添加这行。
FstAlLabel.image = FstAlien
英文:
Welcome, Abdullah. You need pack your label (FstAlLabel
) not your image object (FstAlien
). Here's one way.
FstAlien = ImageTk.PhotoImage(Image.open("alien.jpg"))
FstAlLabel = tk.Label(CHONE_2Sc, image=FstAlien)
FstAlLabel.pack()
If that doesn't work, add this line at the end too.
FstAlLabel.image = FstAlien
答案2
得分: 0
以下是翻译好的部分:
Tkinter how to insert image using Pillow
你仍然有一个
grid(row=100, column=100)
的布局问题。你还搞乱了grid()
我将
pack()
更改为grid()
我不明白
.show()
。你从哪里得到的?代码片段:
import tkinter as tk from PIL import Image, ImageTk CHONE_2Sc = tk.Tk() CHONE_2Sc.configure(background="lime") CHONE_2Sc.title("ROCK, PAPERS, SCISSORS") FstAlien = ImageTk.PhotoImage(Image.open("p1.png")) FstAlLabel = tk.Label(CHONE_2Sc, image=FstAlien) # FstAlien.show(command="display") FstAlLabel.grid(row=0, column=1) Object = tk.Entry() Object.grid(row=1, column=1) Object.insert(0, "输入你的对象:") Object.get() CHONE_2Sc.mainloop()
截图:
英文:
> Tkinter how to insert image using Pillow
You still have grid(row=100, column=100)
layout problem. You also messed up grid()
I changed pack()
to grid()
I do not understand .show()
. Where did you get that?
Snippet:
import tkinter as tk
from PIL import Image, ImageTk
CHONE_2Sc = tk.Tk()
CHONE_2Sc.configure(background="lime")
CHONE_2Sc.title("ROCK,PAPERS,SCISSORS")
FstAlien = ImageTk.PhotoImage(Image.open("p1.png"))
FstAlLabel = tk.Label(CHONE_2Sc, image=FstAlien)
#FstAlien.show(command= "display")
FstAlLabel.grid(row=0, column=1)
Object = tk.Entry()
Object.grid(row=1, column=1)
Object.insert(0, "Enter your object: ")
Object.get()
CHONE_2Sc.mainloop()
Screenshot:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论