[Tkinter-discuss] adjust the size of two canvas when I resize

zizou afix ziz.root at gmail.com
Sun Jun 20 04:06:45 CEST 2010


Hi,
i'm a new user of tkinter,
I would like to adjust my canevas to the main window when a resize it.
i've just find this on the web :
http://infohost.nmt.edu/tcc/help/pubs/tkinter/layout-mgt.html#root-resize
but in my case that don't work

this is my code :
2 canvas and 2 scrollbars
it runs but it does not fit at the window
if someone can help me, very very thanks

#####################################################################################
from Tkinter import *

class Application(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.grid(sticky=N+S+E+W)
        self.canCompose()

    def canCompose(self):
        top=self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(1, weight=1)

        self.canCompose = Canvas(self, width = 800, height = 400 ,bg =
'red', scrollregion=(0,0,100,400))
        self.canComposeTitle = Canvas(self, width = 100, height =400 ,bg =
'blue', scrollregion=(0,0,0,400))

        self.canComposeTitle.grid(row=0, column=0,
            sticky=N+S+E+W)
        self.canCompose.grid(row=0, column=1,
            sticky=N+S+E+W)

        self.scrollCompose_y = Scrollbar(self, orient='vertical')
        self.scrollCompose_y.config(command = self.twoScroll)
        self.scrollCompose_x = Scrollbar(self, orient='horizontal',
                command=self.canCompose.xview)

        self.canComposeTitle['yscrollcommand'] = self.scrollCompose_y.set
        self.canCompose['yscrollcommand'] = self.scrollCompose_y.set
        self.canCompose['xscrollcommand'] = self.scrollCompose_x.set
        self.scrollCompose_y.grid(row=0, column=2,sticky=N+S)
        self.scrollCompose_x.grid(row=1, column=0, columnspan=2, sticky=E+W)

    def twoScroll(self, *args):
        """Send y scroll *args to the two canvas"""
        self.canCompose.yview(*args)
        self.canComposeTitle.yview(*args)
        print args

app = Application()
app.master.title("Sample application")
app.mainloop()
#####################################################################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100620/a0884c94/attachment.html>


More information about the Tkinter-discuss mailing list