Canvases not resizable?

Stuart Reynolds S.I.Reynolds at cs.bham.ac.uk
Thu Aug 19 11:30:13 EDT 1999


Are Tkinter canvases fixed to one size? I don't seem to be able to get
them to expand to fill their container when its resized even the though
the canvas pack options are set to fill=BOTH  and expand=1.

The example both creates a Frame with a canvas. Resizing the frame
doesn't change the size of the canvas.

Stuart


---------

from Tkinter import *



class CFrame(Frame):
    """A Frame containing a Canvas
    """
    def __init__(self, w, h):
	Frame.__init__(self, master=None)

	#Set the frame's width and height
	self["width"] = w
	self["height"] = h

	#Create a red canvas
	self.canvas = Canvas(master=self, bg="red")

	#Print canvas dimensions when clicked
	self.canvas.bind("<Button-1>", self.printCanvasSize)

	#These should make the canvas fill the frame right??
	self.canvas.pack(fill=BOTH, expand=1)


    def printCanvasSize(self, point):
	print 'w = ', self.canvas["width"]
	print 'h = ', self.canvas["height"]


if __name__ == '__main__':
    
    cframe = CFrame(w="8i", h="8i")
    Pack.config(cframe)
    cframe.mainloop()




More information about the Python-list mailing list