Skip to content
Advertisement

Tkinter: Mouse drag a window without borders, eg. overridedirect(1)

Any suggestions on how one might create event bindings that would allow a user to mouse drag a window without borders, eg. a window created with overridedirect(1)?

Use case: We would like to create a floating toolbar/palette window (without borders) that our users can drag around on their desktop.

Here’s where I’m at in my thinking (pseudo code):

  1. window.bind( '<Button-1>', onMouseDown ) to capture the initial position of the mouse.

  2. window.bind( '<Motion-1>', onMouseMove ) to track position of mouse once it starts to move.

  3. Calculate how much mouse has moved and calculate newX, newY positions.

  4. Use window.geometry( '+%d+%d' % ( newX, newY ) ) to move window.

Does Tkinter expose enough functionality to allow me to implement the task at hand? Or are there easier/higher-level ways to achieve what I want to do?

Advertisement

Answer

Yes, Tkinter exposes enough functionality to do this, and no, there are no easier/higher-level ways to achive what you want to do. You pretty much have the right idea.

Here’s one example, though it’s not the only way:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement