Tkinter Canvas/Grid question
Michael Peuser
mpeuser at web.de
Thu Sep 11 03:40:42 EDT 2003
Hi Gary
> from Tkinter import *
>
> class Test(Frame):
> def __init__(self, parent):
> Frame.__init__(self, parent)
> frame = Frame(parent)
There is some confusion here: self *is* the frame, no need or use to make
another....
> self.canvas = Canvas(frame, bg='white' , width=300, height=100)
There is some trick needed here: add:
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
> self.canvas.grid(row=0, column=0, sticky='NESW')
> frame.grid()
This packs the frame to the parent, so it limits the size of your frame in
any case
I should recommend pack in this place (which is possible, because it's
another frame)
Altogether it shall look as follows and work fine:
def __init__(self, parent):
Frame.__init__(self, parent)
self.pack(fill=BOTH,expand=1)
self.canvas = Canvas(self, bg='white' , width=300, height=100)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.canvas.grid(row=0, column=0, sticky='nesw')
More information about the Python-list
mailing list