Tkinter中未显示图像

时间:2018-11-19 14:25:18

标签: python tkinter

我正在用tkinter在python中创建GUI应用程序。菜单栏中有一个帮助菜单,单击该菜单会打开新窗口。该窗口上有3张图像,但它们没有显示,并且该窗口上还有滚动条

使用tkinter python的GUI应用程序。

from tkinter import *

    class Window:
        def __init__(self, master):

            menu = Menu(master)
            master.config(menu=menu)
            file = Menu(menu)
            menu.add_command(label="Help", command=self.show_help)

        def show_help(self):
            global new_help
            new_help = Toplevel(root)
            new_help.title("Help")
            new_help.geometry("650x550+490+100")
            new_help.resizable(FALSE, FALSE)
            global hp_canvas, hp_frame_can
            hp_canvas = Canvas(new_help, bg="#FFF0F5", height=540, width=605)
            hp_canvas.pack(side=LEFT, padx=8)
            hp_scroll = Scrollbar(new_help, command=hp_canvas.yview)
            hp_scroll.pack(side=LEFT, fill=Y)
            hp_canvas.configure(yscrollcommand=hp_scroll.set)
            hp_canvas.bind('<Configure>', self.hp_on_conf)
            hp_frame_can = Frame(hp_canvas)
            hp_canvas.create_window((5, 5), window=hp_frame_can, anchor='nw')
            global canvas1, canvas2, canvas3
            step_1 = Label(hp_frame_can, text="Step 1 ", height=2,
                           width=90, bg="#f0fff0", anchor=W)
            step_1.pack(side=TOP, pady=5)
            canvas1 = Canvas(hp_frame_can, width=460, height=260, bg='blue')
            canvas1.pack()
            gif1 = PhotoImage(file='E:/deepak/image/img1.png')
            canvas1.create_image(0, 0, image=gif1, anchor=NW)

            step_2 = Label(hp_frame_can, text="Step 2 ", height=2,
                           width=90, bg="#f0fff0", anchor=W)
            step_2.pack(side=TOP, pady=5)
            canvas2 = Canvas(hp_frame_can, width=455, height=255, bg='blue')
            canvas2.pack()
            gif2 = PhotoImage(file='E:/deepak/image/img2.png')
            canvas2.create_image(0, 0, image=gif2, anchor=NW)

            step_3 = Label(hp_frame_can,text="Step 3 ", height=2,
                           width=90, bg="#f0fff0", anchor=W)
            step_3.pack(side=TOP, pady=5)
            canvas3 = Canvas(hp_frame_can, width=451, height=254, bg='blue')
            canvas3.pack()
            gif3 = PhotoImage(file='E:/deepak/image/img3.png')
            canvas3.create_image(0, 0, image=gif3, anchor=NW)

        def hp_on_conf(self, event):
            global hp_canvas
            hp_canvas.configure(scrollregion=hp_canvas.bbox('all'))

    if __name__ == '__main__':
        root = Tk()
        root.config(background='#C0C0C0')
        root.title("Demo")
        root.geometry("1000x650+280+70")
        root.resizable(FALSE, FALSE)
        app = Window(root)
        root.mainloop()

0 个答案:

没有答案