tkinter to display the images

前端 未结 1 1049
慢半拍i
慢半拍i 2021-01-28 14:27

I am a newbie to python.I have a code where the image is not printed on the Tkinter.So please help me on how to display the image along with the Button and Textbox.

Code

相关标签:
1条回答
  • 2021-01-28 14:58

    You have to save a reference to the photo image.

    See this page for more information, or this one

    There are numerous other problems with the code you posted, however; you need colons after function and class declarations, for example. When posting code, there's also no need for extraneous methods in the class, they only make it more difficult to understand

    You also cannot mix managers or you're whole program might stall. This means you shouldn't be using pack and grid in the same program. Read through the effbot tutorial, it's really helpful!

    class myproject(Tkinter.Tk):
            def __init__(self,parent):
                Tkinter.Tk.__init__(self)
    
                self.image()
    
    
            def image(self):
    
                logo = Tkinter.PhotoImage(file='linux.gif')
                self.logo = logo # You always need a reference to the image or it gets garbage collected
                w1 = Tkinter.Label(self, image=logo).grid()
    
    
    app = myproject(None)
    app.mainloop()
    
    0 讨论(0)
提交回复
热议问题