Search code examples
pythontkinterscale

how to get position of thumb (in pixels) inside of vertical scale widget relatively upper right corner?


Is there a way to get a position of thumb in pixels in vertical scale widget relative to upper right corner of widget? I want a label with scale value to pop up next to thumb when mouse pointer hovering over it, for this I need thumb coordinates.


Solution

  • The coords method returns the location along the trough corresponding to a particular value.

    This is from the canonical documentation for the coords method:

    Returns a list whose elements are the x and y coordinates of the point along the centerline of the trough that corresponds to value. If value is omitted then the scale's current value is used.

    Note: you asked for coordinates relative to upper-right corner. These coordinates are relative to the upper-left. You can get the width of the widget with winfo_width() and do a simple transformation.