Search code examples
pythontkinter

Tkinter slider bar label. I am unsure how to remove the slider Label or change its text


I have a slider bar that will update the SQLite statement by alphabet. however the label shows the numeric value of the slider bar. I would like to either change this value to represent the correct alphabet setting or hide this label here is an example application

from tkinter import *
#import string

frm = Tk()
def vscale_cb(value):
    #print('vertical: {v}'.format(v=value))
    number=int(value)
    print(chr(ord('@')+number))
    lbl.configure(text=chr(ord('@')+number))

lbl=Label(frm,text='A')
lbl.pack()

sb = Scale(frm, from_=1, to=26, command=vscale_cb)
sb.pack()

mainloop()

Also the code I us to get the Alphabet letter is by using:

chr(ord('@')+number)

I have tried to remove it by using sb.configure(label=chr(ord('@')+number)) or setting the text and or label but no luck. I am not sure if it can be changed or hidden


Solution

  • You can hide it using the showvalue parameter

    from tkinter import *
    #import string
    
    frm = Tk()
    def vscale_cb(value):
        #print('vertical: {v}'.format(v=value))
        number=int(value)
        print(chr(ord('@')+number))
        lbl.configure(text=chr(ord('@')+number))
    
    lbl=Label(frm,text='A')
    lbl.pack()
    
    sb = Scale(frm, from_=1, to=26, command=vscale_cb, showvalue=0)
    sb.pack()
    
    mainloop()