Here is a somewhat inconvenient workaround for this error, using some ideas and code from Brian Oakley, an answer to Dynamically changing the scaling value of tkinter python 2.7 , where Brian shows how to replace a normal display of values with a custom formatted display. Unfortunately, we need to do a little more work, because even when we create Scale with showvalue=False , it is still blocked by floating point numbers that contain commas, even if they don't even display them!
The solution is to make the numbers be integers. This is easy enough to do if the to and from_ are integers with a resolution number, as shown below.
import Tkinter as tk import locale locale.setlocale(locale.LC_NUMERIC, 'pl_PL.UTF8') class NewScale(tk.Frame): def __init__(self, master=None, **options): tk.Frame.__init__(self, master)
This code has been tested on Python 2.6.6 and 3.6.0. To run it in Python 3, change import Tkinter as tk to import Tkinter as tk .
The NewScale widget supports the orientation of tk.VERTICAL and tk.HORIZONTAL , with tk.VERTICAL being standard (the same as the normalScale widget). Its support for the digits option is currently quite primitive.
Here are some ways that make NewScale more useful:
def get(self): return self.scale.get() * self.res def set(self, value): self.scale.set(int(0.5 + value / self.res))
To test these methods, change the calling code to:
if __name__ == '__main__': master = tk.Tk() w = NewScale(master, from_=0.05, to=0.1, resolution=0.01) w.pack(fill='both', expand=True) w.set(0.07) tk.Button(master, text='Print', command=lambda: print(w.get())).pack() master.mainloop()
And it's probably a good idea to round off the adjusted values of to and from_ to the nearest whole number, rather than trimming them. This can be done by changing their initializers to:
from_ = int(0.5 + options.get('from_', 0) / self.res) to = int(0.5 + options.get('to', 100) / self.res)