python - Tkinter-PhotoImage in a Tkinter.Frame -


i trying add photoimage() in 1 of frame-widgets. there seem problem though since graphics of picture won't show.

code below:

        urllib import urlopen     import tkinter     tkinter import *      class frames(object):          pictures = {"path": "c:/users/xxxxx/desktop/source/pics/",                     'google': 'google.gif',                     'wiki': 'wikipedia.gif',                     'tyda': 'tyda.gif',                     "hitta": "hitta.gif"                     }          def __init__(self, parent):              #creation of main frames             self.parent = parent             self.logo_frame = frame(parent)             self.input_frame = frame(parent)             self.output_frame = frame(parent)          def configure(self):             #root window             self.parent.geometry('400x400')             self.parent.title('w0rksuite')             self.parent.configure(bg='grey')             ################################################################             #geometry logo_frame             self.logo_frame.configure(bg='white', width=385, height=45)             self.logo_frame.grid(column=0, row=0, padx=6, pady=4)             ################################################################             #geometry input_frame             self.input_frame.configure(bg='white', width=385, height=45)             self.input_frame.grid(column=0, row=1, padx=6, pady=4)               ################################################################             #geometry output_frame             self.output_frame.configure(bg='white', width=385, height=280)             self.output_frame.grid(column=0, row=2, padx=6, pady=4)             ################################################################          def frame_objects(self):             #input entry             input_entry = entry(self.input_frame, width=55)             input_entry.grid(column=0, row=1)             #input text             input_text = label(self.input_frame, text='search:')             input_text.grid(column=0, row=0, sticky=w)             input_button = button(self.input_frame, text='find')             #input_button.configure(height=)             input_button.grid(column=2, row=1, padx=3, pady=0)             #image objects             hitta_pic = photoimage(file=frames.pictures['path']+frames.pictures['hitta'])             hitta_button = button(self.logo_frame, image=hitta_pic)             hitta_button.grid(column=0, row=0, sticky=w)    #initiate windows############# root = tk() master_frames = frames(root) master_frames.configure() master_frames.frame_objects() root.mainloop() ############################## 

my bolded text how make photoimage , connect frame. button appears, there's no graphic picture.

if in separate python-file try functionality, whether or not button-image can added frame, works , picture shows.

any ideas on why grapgics won't show?

(example test works): import tkinter tkinter import *

root = tk() frame = frame(root) image = photoimage(file='c:/users/xxxxxxx/desktop/source/pics/hitta.gif') button = button(frame, image=image) button.pack() frame.pack() root.mainloop() 

actually, answered putting piece of code @ end of question show works:

root = tk() frame = frame(root) image = photoimage(file='c:/users/xxxxxxx/desktop/source/pics/hitta.gif') button = button(frame, image=image) button.pack() frame.pack() root.mainloop() 

here image object not destroyed , stays in memory can reference , still has data, in frame_objects(self) method of frames(object) created object :

hitta_pic = photoimage(file=frames.pictures['path']+frames.pictures['hitta']) 

this object gets destroyed each time return frame_objects(self), nothing displayed, 1 work around make object attribute of class frames(object), way:

self.hitta_pic = photoimage(file=frames.pictures['path']+frames.pictures['hitta'])  

but whenever need reference object, have similar this:

hitta_button = button(self.logo_frame, image=self.hitta_pic)#here associate name of object self keyword. 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -