PNG将不会在弹出窗口Tkinter中显示

Zayn贾斯汀

尽管img的变量是全局变量,但我的PNG文件不会显示在弹出窗口中。

global img

def Malwind():
    maltop = Toplevel()
    maltop.iconbitmap('icon.ico')
    maltop.title("Expert Systems Diagnosis Results")
    mgt1 = Label(maltop, text="The breast lump is diagnosed to be: Malignant").grid(row=5, column=2)
    mgt2 = Label(maltop, text="The following symptoms could be observed").grid(row=6, column=2)
    mgt3 = Label(maltop, text="Skin irritation\nPain or tenderness of the nipple\nBloody nipple discharge").grid(row=7, column=2)
    canvas = Canvas(maltop, width = 200, height = 200)
    canvas.grid(row = 1, column = 2)
    img = ImageTk.PhotoImage(Image.open("soft.png"))
    canvas.create_image(0, 0, anchor = NW, image = img)
小鸭

所述Global关键字被认为是一个函数内,并允许在函数的函数中的全局范围修改变量的值。这意味着您必须global img进入该函数,并确保此变量已存在于全局范围中。这是更正的代码:

def Malwind():
    global img
    maltop = Toplevel()
    maltop.iconbitmap('icon.ico')
    maltop.title("Expert Systems Diagnosis Results")
    mgt1 = Label(maltop, text="The breast lump is diagnosed to be: Malignant").grid(row=5, column=2)
    mgt2 = Label(maltop, text="The following symptoms could be observed").grid(row=6, column=2)
    mgt3 = Label(maltop, text="Skin irritation\nPain or tenderness of the nipple\nBloody nipple discharge").grid(row=7, column=2)
    canvas = Canvas(maltop, width = 200, height = 200)
    canvas.grid(row = 1, column = 2)
    img = ImageTk.PhotoImage(Image.open("soft.png"))
    canvas.create_image(0, 0, anchor = NW, image = img)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Facebook分享按钮将不会在Chrome中显示

来自分类Dev

Nexus 5将不会在Eclipse中显示

来自分类Dev

<div>将不会在Ruby on Rails中显示

来自分类Dev

Tkinter按钮将不会在画布上滚动

来自分类Dev

如果调用revokeObjectURL,则Blob图片将不会在Chrome中显示

来自分类Dev

SSID将不会在Ubuntu MATE上显示

来自分类Dev

QT QPixmap将不会在QScrollArea中滚动

来自分类Dev

Monodevelop将不会在Mint 17中启动

来自分类Dev

Elasticsearch将不会在Ubuntu 18.04.4 LTS中启动

来自分类Dev

QT QPixmap将不会在QScrollArea中滚动

来自分类Dev

剧情不会在Jupyter中显示

来自分类Dev

图片不会在wordpress中显示

来自分类Dev

图像不会在 xamarin 中显示

来自分类Dev

片段不会在活动中显示

来自分类Dev

从C#中的原始像素数据创建的位图将不会在IE中显示

来自分类Dev

新窗口加载永远不会在 javascript 中触发

来自分类Dev

创建一个不显示桌面且不会在启动器中显示的Gtk窗口

来自分类Dev

不会在弹出窗口中触发chrome.tabs.create的回调吗?

来自分类Dev

在git中创建的分支不会在eclipse中显示

来自分类Dev

javascript,jquery将不会在15英寸的屏幕上显示图像

来自分类Dev

“文件”,“编辑”等将不会在Cinnamon Desktop Ubuntu 16.04LTS上显示

来自分类Dev

使用CorelDraw创建的SVG将不会在iOS上显示文本

来自分类Dev

Firefox不会在浏览器中显示日志

来自分类Dev

content:url(); 不会在Firefox中显示我的图像

来自分类Dev

Matplotlib不会在图例中显示修补程序的填充

来自分类Dev

启动画面不会在JAR中显示

来自分类Dev

使用Chrome时,图片不会在div中显示

来自分类Dev

Tableview不会在Swift 2中显示数据

来自分类Dev

颜色不会在自定义类别中显示

Related 相关文章

热门标签

归档