I'd like to be able to make a slider widget without the knob that users can click and drag -- that is, I want the user to simply click somewhere on an empty slider and *then* have the knob appear where clicked. Is this possible with either Tkinter or wxPython? (Or another toolkit?)

Essentially I'm looking for a person's rating of a given object (i.e., how bright is it?), so they should only have to click once. I know that radio buttons can do the job, and that's what I'm using currently, but they seem rather cumbersome and less suggestive of the truly scalar nature of the object's quality (brightness, complexity, etc.).

You can manually script your own widget for Tkinter. Google it. I haven't tried myself, but what you seem to be wanting could be done easily with a custom widget.

Heh... easier than just using radio buttons? Now there's the question.

But thanks. I'll have a look at the widget coding and see if I can get my head around it.

I think Tkinter is written in TCL language with a Python wrapper hanging over it. If you want to write a new widget you better learn TCL.

I fooled around a little with the scale widget itself and mouse events and came up with this:

# experiment with Tkinter's Scale widget
# make the slider respond to mouse clicks

import Tkinter as tk

def position(event):
    # let's assume the position is from 0 to 100
    # to match the scales min/max or from_/to value
    position = 100 * event.x/scale_len
    # show result in title bar (test)
    str1 = "position = %d" % position
    root.title(str1)
    # set the slider to the new position
    scale1.set(position)

root = tk.Tk()

scale_lbl = "Click on the scale"
scale_val = tk.IntVar()
scale_len = 300
scale1 = tk.Scale(root, label=scale_lbl, variable=scale_val,
    from_=0, to=100, tickinterval=25, length=scale_len,
    sliderlength=8, orient='horizontal')
scale1.pack(side='left')
scale1.bind("<Button-1>", position)

root.mainloop()

Noticed some strange effect:
keeping the mouse pressed below position 38 inside the dark scale area makes the slider wander lower! Don't ask me why.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.