0

I'm beginner, I'm trying to setup the scroll on a Tkinter window. But I can scroll to up and down to infinite. I didn't find how I can block the scroll when I see the up of the canvas and the down. Please help me.

def on_scroll(self, *args):
        # Obtenir la position actuelle de la barre de défilement
        position = float(args[0])

        # Obtenir les coordonnées du canvas
        bbox = self.canvas.bbox(tk.ALL)

        # Autoriser le défilement vers le haut seulement si le haut du canvas n'est pas visible
        if position < 1.0 and bbox[1] < 0:
            self.canvas.yview_scroll(-1, "units")
        # Autoriser le défilement vers le bas seulement si le bas du canvas n'est pas visible
        elif position > 0.0 and bbox[1] + bbox[3] > self.canvas.winfo_height() and self.canvas.yview()[1] < 1.0:
            self.canvas.yview_scroll(1, "units")

        # Ajuster la position du bouton en fonction de la hauteur totale de l'écran
        screen_height = self.root.winfo_screenheight()
        self.canvas.coords(self.validbutton_window, self.canvas.winfo_reqwidth() - 100, screen_height - 30)

I tried so many things but it was always a fail. I just want to can scroll but the scroll stops when the end of the canvas arrive to the end of the window some for up. sorry for my englsih.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.