Skip to content Skip to sidebar Skip to footer

How To Create Multiple, Different Custom Scales In Tkinter Gui?

I'm trying to create two custom scales in one GUI. The simplest way to create a custom scale is by using a style; but the problem is that when this function is called for the secon

Solution 1:

I managed to solve the problem. Leaving it for record to anyone who might need it. The root of the problem is the fact that "custom.Horizontal.Scale.trough" can not be used twice. Modifying it to "custom.Horizontal.Scale.trough2" or "custom.Horizontal.Scale2.trough" does not work. However, modifying the string "custom" can work. It is possible to use a different string everytime this function is called without affecting the functionality. This is what I did:

i=1
def create_style():
    global img_trough
    global img_slider
    global startup
    global i
    if startup=="no":
        img_trough = PhotoImage(file="bar.gif")
        img_slider = PhotoImage(file="slider.gif")

    if startup=="yes":
        img_trough = PhotoImage(file="bar_small.gif")
        img_slider = PhotoImage(file="slider_small.gif")


    print("called", i, "th time")
    i=i+1
    # create scale elements
    string_trough=str(i)+'.custom.Horizontal.Scale.trough'
    string_slider=str(i)+'.custom.Horizontal.Scale.slider'
    style.element_create(string_trough, 'image', img_trough)
    style.element_create(string_slider, 'image', img_slider)
    # create custom layout
    style.layout('custom.Horizontal.TScale',[(string_trough, {'sticky': 'ns'}),(string_slider, {'side': 'left', 'sticky': '','children': [('custom.Horizontal.Scale.label', {'sticky': ''})]})])

Post a Comment for "How To Create Multiple, Different Custom Scales In Tkinter Gui?"