[Tkinter-discuss] Getting a canvas within an existing frame.

Michael Lange klappnase at web.de
Thu Apr 22 11:08:59 CEST 2010


Hi,

On Wed, 21 Apr 2010 18:38:06 -0700 (PDT)
kimmyaf <flahertyk1 at hotmail.com> wrote:

> 
> I cannot get my canvas to show within my existing frame.  I can only
> get it to build it's own frame. Can someone help? As you can see i've
> tried a number of different things so i have a lot of stuff commented
> out at the bottom. attached is a picture of what my GUI looks like. I
> want the canvas to show in the same frame as the address entries not
> seperately. Any help is appreciated. I see a lot of examples on the
> web but they are all building the canvas in their own frame. I need
> it in the other frame.
> 

>From your code and the screenshot I am not sure what exactly did not
work for you. The screenshot shows the canvas in a second window, which
works but is apparently not what you want (BTW, in your code you use a
second instance of Tkinter.Tk() to open the second window, which is one
of the upper case "don't"s in Tkinter :) If you need a second window
you should use Tkinter.Toplevel() instead).
>From the commented out parts of your code I think you meant to do:

        #define a new frame and put a text area in it
        self.imgframe=Frame(self.frame)
        
        #tkinter_phimg = ImageTk.PhotoImage(i)  # can do only after Tk()! 
        self.canvas = Tkinter.Canvas(self.imgframe, width=50, height=50)
        self.canvas.pack()

Not sure what you tried already, but here self.imgframe is never pack()ed,
so maybe the solution is as simple as that? Or, have you tried to omit
self.imgframe and put the canvas directly into self.frame , and if yes,
what exactly happened?

Regards

Michael


More information about the Tkinter-discuss mailing list