Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将JPEG图像插入python Tkinter窗口?_Python_Image_Tkinter_Window_Jpeg - Fatal编程技术网

如何将JPEG图像插入python Tkinter窗口?

如何将JPEG图像插入python Tkinter窗口?,python,image,tkinter,window,jpeg,Python,Image,Tkinter,Window,Jpeg,如何将JPEG图像插入Python 2.7 Tkinter窗口?以下代码有什么问题?该图像名为Aaron.jpg 试试这个: import tkinter as tk from PIL import ImageTk, Image #This creates the main window of an application window = tk.Tk() window.title("Join") window.geometry("300x300") window.configure(back

如何将JPEG图像插入Python 2.7 Tkinter窗口?以下代码有什么问题?该图像名为Aaron.jpg

试试这个:

import tkinter as tk
from PIL import ImageTk, Image

#This creates the main window of an application
window = tk.Tk()
window.title("Join")
window.geometry("300x300")
window.configure(background='grey')

path = "Aaron.jpg"

#Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
img = ImageTk.PhotoImage(Image.open(path))

#The Label widget is a standard Tkinter widget used to display a text or image on the screen.
panel = tk.Label(window, image = img)

#The Pack geometry manager packs widgets in rows or columns.
panel.pack(side = "bottom", fill = "both", expand = "yes")

#Start the GUI
window.mainloop()

相关文档:,

您在这方面花了多长时间?嗯。。。分机是干什么的?也许没必要这么说。。。“请修复代码并粘贴到下面!”您得到的错误是什么?检查并查看是否存在问题persists@dilbert六年过去了(:注意,原来的PIL不能与Python 3一起使用,但Pillow几乎是一个替代品:Re@Caspar的评论,在Python 3(.6)的命令行中,do
pip install Pillow
来获取模块。注意,额外的“弹出窗口”包含图像的窗口也需要在标签实例化之外指定图像(例如
Label=tk.Label(window,image=img)
然后
Label.image=img
,最后
Label.pack()
)请添加一些关于这里是什么的解释
import tkinter as tk
from PIL import ImageTk, Image

#This creates the main window of an application
window = tk.Tk()
window.title("Join")
window.geometry("300x300")
window.configure(background='grey')

path = "Aaron.jpg"

#Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
img = ImageTk.PhotoImage(Image.open(path))

#The Label widget is a standard Tkinter widget used to display a text or image on the screen.
panel = tk.Label(window, image = img)

#The Pack geometry manager packs widgets in rows or columns.
panel.pack(side = "bottom", fill = "both", expand = "yes")

#Start the GUI
window.mainloop()
import tkinter as tk
from tkinter import ttk
from PIL import Image,  ImageTk
win = tk. Tk()
image1 = Image. open("Aoran. jpg")
image2 =  ImageTk. PhotoImage(image1)
image_label = ttk. Label(win , image =.image2)
image_label.place(x = 0 , y = 0)
win.mainloop()
from tkinter import *
from PIL import ImageTk, Image

window = Tk()
window.geometry("1000x300")

path = "1.jpg"

image = PhotoImage(Image.open(path))

panel = Label(window, image = image)

panel.pack()

window.mainloop()