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

一.如果像下面代码一样,将图片的录入放到了一个方法里面,那么需要对图片 tem_img0 = ImageTk.PhotoImagetem_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)

猜你喜欢

转载自blog.csdn.net/weixin_43134049/article/details/120520982
今日推荐