tkinter: How to autoscroll with middle mouse button?


哈格(Haggar)

Right now, I have an implementation that does two things with the middle mouse button:

  1. Scroll the wheel to zoom in and out
  2. Roll the wheel button to scroll (pan) left, right, top and bottom. But in this function, I keep pressing the scroll button to scroll.

What I want to do is:

  1. Press and release the middle mouse button to enter scroll mode.
  2. Then simply move the mouse left and right and up and down to scroll in all directions.
  3. When done, press and release the middle mouse button to exit this mode.

Just like how it is implemented in MS Word or Chrome browsers.

help!

Steven Summers

This is the quick and easy thing I believe you are after.

import tkinter as tk

root = tk.Tk()

pressed = False

def onClick(event):
    global pressed
    pressed = not pressed # toggle pressed when clicked
    print('Pressed')

def onMove(event):
    if pressed:
        print(event.x, event.y)

root.bind('<Button-2>', onClick)
root.bind('<Motion>', onMove)

root.mainloop()

Related


tkinter: How to autoscroll with middle mouse button?

哈格(Haggar) Right now, I have an implementation that does two things with the middle mouse button: Scroll the wheel to zoom in and out Roll the wheel button to scroll (pan) left, right, top and bottom. But in this function, I keep pressing the scroll button to

tkinter: How to autoscroll with middle mouse button?

哈格(Haggar) Right now, I have an implementation that does two things with the middle mouse button: Scroll the wheel to zoom in and out Roll the wheel button to scroll (pan) left, right, top and bottom. But in this function, I keep pressing the scroll button to

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to map the middle mouse button for double click?

Kira Ubuntu 18.04. When I click the middle mouse button, it should double click. thanks. Edit: Using the Unity desktop. unknown OS: Ubuntu 18:04 Required packages: xdotoolandxbindkeys you can install these packagessudo apt install xdotool xbindkeys gedit .xbin

How to enable middle mouse button in Ubuntu 16.04?

Eli Erding The issue is specific to the solution in the given version (16.04). Feel free to mark this as a duplicate, but it was created for the latest version user's solution. We can't simply google any solution for 16.04 and keep looking for it . Ok, I try t

How to enable middle mouse button in Ubuntu 16.04?

Eli Erding The issue is specific to the solution in the given version (16.04). Feel free to mark this as a duplicate, but it was created for the latest version user's solution. We can't simply google any solution for 16.04 and keep looking for it . Ok, I try t

How to disable middle mouse button click?

hardcode My mouse is faulty and the middle mouse button is always pressed, but I don't know how to disable the click function. I've looked at the mouse settings, but I can't change the function of the middle mouse button at all. I still want to be able to scro

How to enable paste into terminal with (middle) mouse button

count 0 After that apt-get update && apt-get upgrademy middle mouse button paste stopped working on Xserver/12.04.2 LTS. This may also be due to apt-get autoremoverunning after I just ran it, but I can't remember the specific point when it stopped working. Bas

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to simulate middle mouse button in selenium?

Ovicon So, I'm inside a google classroom with 8 classes and I want selenium to middle click and open those classes in a new tab. For example, here is one of my classes, I have it find an element by xpath, I want selenium to open this element in a new tab by mi

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to enable paste into terminal with (middle) mouse button

count 0 After that apt-get update && apt-get upgrademy middle mouse button paste stopped working on Xserver/12.04.2 LTS. This may also be due to apt-get autoremoverunning after I just ran it, but I can't remember the specific point when it stopped working. Bas

How to enable middle mouse button in Ubuntu 16.04?

Eli Erding The issue is specific to the solution in the given version (16.04). Feel free to mark this as a duplicate, but it was created for the latest version user's solution. We can't simply google any solution for 16.04 and keep looking for it . Ok, I try t

How to enable middle mouse button in Ubuntu 16.04?

Eli Erding The issue is specific to the solution in the given version (16.04). Feel free to mark this as a duplicate, but it was created for the latest version user's solution. We can't simply google any solution for 16.04 and keep looking for it . Ok, I try t

How to disable middle mouse button click?

hardcode My mouse is faulty and the middle mouse button is always pressed, but I don't know how to disable the click function. I've looked at the mouse settings, but I can't change the function of the middle mouse button at all. I still want to be able to scro

How to enable paste into terminal with (middle) mouse button

count 0 After that apt-get update && apt-get upgrademy middle mouse button paste stopped working on Xserver/12.04.2 LTS. This may also be due to apt-get autoremoverunning after I just ran it, but I can't remember the specific point when it stopped working. Bas

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

Which mouse button is in the middle?

Radu Murzea: I'm currently developing a program in Java where a specific event has to be fired only when the user clicks with the left and right mouse buttons at the same time. Since this is a bit unconventional, I decided to test it first. here is: import jav

Which mouse button is in the middle?

Radu Murzea: I'm currently developing a program in Java where a specific event has to be fired only when the user clicks with the left and right mouse buttons at the same time. Since this is a bit unconventional, I decided to test it first. here is: import jav