3

Is it possible to create a Tkinter scale widget with logaritmic values? Or, kind of, set the ticks to the corresponding value? I need a scale in the range of 10^4 to 10^9, with the exponent in whole numbers.

I was thinking about just labeling the "axis" accordingly, but a 10^x depiction is really more practical and intuitive.

finefoot
  • 9,914
  • 7
  • 59
  • 102
Jakob
  • 1,897
  • 2
  • 16
  • 17

1 Answers1

2
from Tkinter import *

class Slider(Frame):
    def __init__(self, parent=None ):
        Frame.__init__(self, parent)
        self.number = 0
        self.slide = Scale(self, orient=HORIZONTAL, command=self.setValue,
                           length=200, sliderlength=20,
                           showvalue=0, tickinterval=1,
                           fro=4, to=9, font=('Arial',9))
        self.text = Label(self, font=('Arial',18))
        self.slide.pack(side=RIGHT, expand=1, fill=X)
        self.text.pack(side=TOP, fill=BOTH)
        self.unimap = {'4':u'\u2074','5':u'\u2075','6':u'\u2076',
                       '7':u'\u2077','8':u'\u2078','9':u'\u2079'}

    def setValue(self, val):
        self.number = (10**(int(val)))
        self.text.configure(text='10%s' %(self.unimap[val]))

root = Tk()
s = Slider(root)
s.pack()
root.mainloop()

screenshot

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
noob oddy
  • 1,314
  • 8
  • 11