【问题标题】:Cannot display image using python in anaconda jupyter notebook无法在 anaconda jupyter notebook 中使用 python 显示图像
【发布时间】:2020-11-28 04:17:11
【问题描述】:

尽管尝试了多种解决方案,但我可以在这里找到。 似乎图像仍然无法显示。 任何人都可以对此有所了解,将不胜感激。

我正在使用 anaconda Jupiter 笔记本 当前python版本是3.7.3

import tkinter as tk
import os
window = tk.Tk()
window.title("Test")
load = Image.open(r'C:\t.jpg')
render = ImageTk.PhotoImage(load)  
window.mainloop()

【问题讨论】:

    标签: python jupyter-notebook anaconda


    【解决方案1】:

    好的,我现在看到你的问题了。 PhotoImage 将图像加载到内存中,但不绘制它。

    试着把这个放在window.mainloop()之前:

        . . .
    render = ImageTk.PhotoImage(load)
    canvas = new Canvas(window, width=500, height=500) # Change the height and width to suit your image
    canvas.pack() # Put the canvas on the window
    canvas.create_image(0, 0, anchor=NW, image=render) # Put the image on the canvas
    

    【讨论】:

    • 显示语法错误,请指教,谢谢。 File "", line 13 canvas = new Canvas(window, width=500, height=500) # 更改高度和宽度以适合您的图像 ^ SyntaxError: invalid syntax
    • 抱歉,删除“新”。习惯了 C :~)
    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2021-10-27
    • 2023-01-28
    • 2018-07-25
    • 2017-11-13
    • 1970-01-01
    相关资源
    最近更新 更多