-1

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 second time to create the second scale, the style.element_create() generates an error as it sees the 'custom.Horizontal.Scale.trough' as a duplicate.

def create_style():
    global startup
    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")

   # create scale elements
   style.element_create('custom.Horizontal.Scale.trough', 'image', img_trough)
   style.element_create('custom.Horizontal.Scale.slider', 'image', img_slider)
   # create custom layout
   style.layout('custom.Horizontal.TScale',[('custom.Horizontal.Scale.trough', {'sticky': 'ns'}),
            ('custom.Horizontal.Scale.slider', {'side': 'left', 'sticky': '','children': [('custom.Horizontal.Scale.label', {'sticky': ''})]})])
1

1 Answer 1

0

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': ''})]})])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.