在Python中添加图片通常有以下几种方法:
import imageioimage = imageio.imread('image.jpg')imageio.imshow(image)
2. 使用第三方库`PIL`(Pillow):
from PIL import Imageimage = Image.open('image.jpg')image.show()
3. 使用第三方库`OpenCV`:
import cv2image = cv2.imread('image.jpg')cv2.imshow('Image', image)cv2.waitKey(0)cv2.destroyAllWindows()
4. 在图形用户界面(GUI)中添加图片:

使用`PyQt`或`PySide`库:
from PyQt5.QtWidgets import QLabelself.label1 = QLabel(self)self.label1.setPixmap(QPixmap('images/head.jpg'))layout.addWidget(self.label1)
使用`tkinter`库:
from tkinter import Labellabel = Label(root)label.image = PhotoImage(file="image.jpg")label.pack()
5. 使用`matplotlib`库:
import matplotlib.pyplot as pltimport matplotlib.image as mpimgimg = mpimg.imread('image.jpg')plt.imshow(img)plt.show()
请根据您的具体需求选择合适的方法。
