Tkinter Canvas/Grid question

Gary Richardson garyr at fidalgo.net
Wed Sep 10 22:03:18 EDT 2003


Is there a simple way of causing the size of a canvas to change as the
window is resized when using the Grid geometry manager? Setting
sticky='NESW', as in the following code, doesn't work though the
documentation for Grid seems to imply that it should: "sticky   If a
slave's cell is larger than its requested dimensions, this option may be
used to position (or stretch) the slave within its cell. ... The sticky
option subsumes the combination of anchor and fill that is used by
pack". Or is there something wrong with my code?

Thanks,
Gary Richardson

from Tkinter import *

class Test(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        frame = Frame(parent)
        self.canvas = Canvas(frame, bg='white' , width=300, height=100)
        self.canvas.grid(row=0, column=0, sticky='NESW')
        frame.grid()

root = Tk()
Test(root)
root.mainloop()









More information about the Python-list mailing list