栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

tkinter 图片未出现,图片显示窗口错误,记录

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

tkinter 图片未出现,图片显示窗口错误,记录

一.如果像下面代码一样,将图片的录入放到了一个方法里面,那么需要对图片 tem_img0 = ImageTk.PhotoImage 的 tem_img0 声明以下全局变量,不然就是不报错,但也不显示。

二.对于创建的程序有多个窗口,然后副窗口打开图片,结果在主窗口显示了,这里一定要记住 在申明创建的时候把,参数 master=你的窗口类名带上,下面程序我的是 screen_win ,这是一个全局变量 ,创建的时候是 screen_win = tkinter.Tk()

def show_photo_in_screen_wind():
    global tem_img0
    # global tem_img1
    # global screen_win

    global global_tem_state_class
    tem_photo = Image.open(global_tem_state_class.out_tem_path())  # 括号里为需要显示在图形化界面里的图片

    # tem_photo = photo.resize((30, 50))  # 规定图片大小
    tem_img0 = ImageTk.PhotoImage(master= screen_win,image=tem_photo)
    tem_img1 = tkinter.Label(master= screen_win)  # img1.place(x=100, y=130, )
    tem_img1.place(x=600, y=400)
    tem_img1.config(image=tem_img0)
    # tem_img1 = ttk.Label(text="样本:", image=tem_img0)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/272887.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号