Python Tkinter: Canvas scrolling with MouseWheel

前端 未结 2 521
鱼传尺愫
鱼传尺愫 2021-01-14 20:47

I have created a tree inside a Canvas, and I have also allowed MouseWheel to scroll up and down.

However, how do I prevent scrolling if tree content has not exceed c

2条回答
  •  梦毁少年i
    2021-01-14 21:30

    You can use the bbox method of canvas to retrieve the actual height of drawn items on canvas. bbox return a tuple defining a rectangle. You can compare it with the height of your canvas widget.

      height = self.canvas.winfo_height()
      _,_,_,items_height = self.canvas.bbox(Tkinter.ALL)
      if (items_height < height):
         direction = 0
    

提交回复
热议问题