Next mystery :
a picture drawn in the canvas c1 is scrollable.
a picture-containing canvas "grided" in the canvas c1 is not.

so why ???
Marion
---------------------------------------------------------------
from tkinter import *
from PIL import *

class Main:
    def __init__(self):
## Main window
        self.root = Tk()
        self.root.grid_rowconfigure(0, weight=1)
        self.root.grid_rowconfigure(1, weight=1)
        self.root.grid_columnconfigure(0, weight=1)
## datas : 
        self.PIC=[]
        self.ANN=[]
        
## First canvas (picture)
        self.c1 = Canvas(
            self.root,
            width=500,
            height=100,
            bd=2,
            relief=SUNKEN,
            scrollregion=(0, 0, 100, 100))
        
        self.c1.grid(
            row=0,rowspan=2,
            column=1,
            sticky='nswe')
        
#-------------------------------#
# this is scrollable :
#-------------------------------#
        image  =Image.new("RGB",(100,100))
        dessin = ImageDraw.Draw(image)
        dessin.rectangle([(10,10),(50,50)],fill="rgb(255,0,0)")
        photo=ImageTk.PhotoImage(image)
        item = self.c1.create_image(0,0,anchor=NW,image=photo)

#-------------------------------#
# this is not ! :
#-------------------------------#
        canvas=Canvas(self.c1,background="WHITE")
        image  =Image.new("RGB",(100,100))
        dessin = ImageDraw.Draw(image)
        dessin.rectangle([(10,10),(50,50)],fill="rgb(255,0,0)")
        photo=ImageTk.PhotoImage(image)
        item = canvas.create_image(0,0,anchor=NW,image=photo)
        canvas.grid()
        
        
## Second canvas (annot)
        c2 = Canvas(
            self.root,
            width=500,
            height=100,
            bd=2,
            relief=SUNKEN,
            scrollregion=(0, 0, 1000, 1000))
        c2.grid(
            row=2,rowspan=2,
            column=1,
            sticky='nswe')
        
## Special function scroll both canvases horizontally
        def xscrollboth(a,*args):
            self.c1.xview(a,*args)
            c2.xview(a,*args)
            
## Horizontal scrollbar for both canvases
        hScroll = Scrollbar(self.root, orient=HORIZONTAL, command=xscrollboth)
        hScroll.grid(
            row=4,rowspan=1,
            column=1,
            sticky='we')
            
## Vertical scrollbars
        vScroll1 = Scrollbar(orient=VERTICAL, command=self.c1.yview)
        vScroll1.grid(
            row=0,rowspan=2,
            column=2,
            sticky='ns')
        self.c1.config(yscrollcommand=vScroll1.set,xscrollcommand=hScroll.set)
        
        vScroll2 = Scrollbar(orient=VERTICAL, command=c2.yview)
        vScroll2.grid(
            row=2,rowspan=2,
            column=2,
            sticky='ns')
        c2.config(yscrollcommand=vScroll2.set,xscrollcommand=hScroll.set)
---------------------------------------------------------------
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to