#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from tkinter import *

def my_yview (*args):
    """
        cette fonction s'intercale entre l'objet Scrollbar() et
        l'objet Canvas() afin d'étudier ce qui se passe lorsque
        l'utilisateur manipule l'objet Scrollbar();
    """
    # on affiche dans la console les arguments passés
    # normalement au callback canvas.yview
    print(*args)
    # on relaie l'info au canvas
    # pour s'assurer du bon fonctionnement
    canvas.yview(*args)
# end def

# on crée la fenêtre principale
fenetre = Tk()
fenetre.rowconfigure(0, weight=1)

canvas = Canvas(fenetre, bg="white", width=200, height=100)
canvas.create_text(100, 50, text="Hello good people!")
canvas.grid(row=0, column=0, sticky=NW+SE)

vbar = Scrollbar(fenetre, orient=VERTICAL)
vbar.grid(row=0, column=1, sticky=NS)

# connexion canvas - scrollbar

canvas.configure(
    yscrollcommand=vbar.set,
    scrollregion=(0, 0, 200, 300),
)

vbar.configure(command=my_yview)

# on lance la boucle principale
fenetre.mainloop()
