Skip to content
Advertisement

A tkinter GUI with a resizable left panel: resizable arrow indicator appearance issue

I created this test code to simulate a Tk window with a left panel that is resizable. How it works:

  1. When the mouse pointer move over the ttk.Separator, a resizable arrow indicator will appear where the mouse pointer is.
  2. Pressing the left mouse button and moving the mouse pointer, the width of the left panel will resize corresponding to the x position of the mouse pointer.
  3. The resizable arrow indicator should also move in sync with the mouse pointer.

I am able to perform steps 1 & 2. However, for step 3, I have an issue. The resizable arrow indicator in step 1 does not disappear while the resizable arrow indicator position in step 3 does follow the mouse pointer occasionally: there appears to be a competition btw these two steps.

How do I fix this issue?

Test code:

JavaScript

resize-arrow-24.png: resize-arrow-24.png

Advertisement

Answer

To resolve my resizable arrow indicator issue, I had to introduce event handlers to unbind and rebind events <Enter> and <Leave> when B1 is pressed and released on the ttk.Separator widget. See revised test code below. See Revised test code.

An enhancement to this script is to transform the mouse pointer appearance into a resizable arrow indicator when it enters the widget ttk.Separator as mentioned by @Atlas435 in the comment section of my question. This can be done by using the cursor option of the ttk.Separator widget. This approach also eliminates needing to implement the solution mentioned above and makes the code more concise. See Improved revised test code

From hindsight, I released I had written a python class to create an alternative vertically oriented ttk.PanedWindow widget using ttk.Frame and ttk.Separator widgets. @BryanOakley and @HenryYik thanks for pointing this fact to me.

Revised test code:

JavaScript

Improved revised test code (a VerticalPanedWindow widget):

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