1

trying to make option list of colours that change the colour of a pattern in canvas

preview = Canvas(window, width=100, height=100, bg="white")
preview.place(x=230,y=170)
global s_fill
s_fill = "purple"
p_selected = 1
def update():
    if p_selected == 1:
        pattern1
    else:
        pattern2

def colour_selected():
    global s_fill
    selected = var2.get()
    if selected == "purple":
        preview.delete("all")
        s_fill = "purple"
        update()
    elif selected == "DarkSlateGray4":
        preview.delete("all")
        s_fill = "DarkSlateGray4"
        update()
    elif selected == "deep sky blue":
        preview.delete("all")
        s_fill = "deep sky blue"
        update()
    elif selected == "light sea green":
        preview.delete("all")
        s_fill = "light sea green"
        update()
    elif selected == "VioletRed2":
        preview.delete("all")
        s_fill = "VioletRed2"
        update()
    elif selected == "gold":
        preview.delete("all")
        s_fill = "gold"
        update()


var2 = StringVar()
c_options = ("purple", "DarkSlateGray4", "deep sky blue", "light sea green", "VioletRed2", "gold")
colour_list = OptionMenu(window, var2, * c_options, command= colour_selected)
colour_list.place(x=40, y=210, width=120, height=25)

i keep getting the error colour_selected() takes 0 positional arguments but 1 was given and i generally just don't know how to fix it.

Yusuf Syam
  • 701
  • 1
  • 4
  • 18

1 Answers1

1

You can make colour_selected ignore any arguments passed to it:

def colour_selected(*_):

(See this question for more about *_.)

legoscia
  • 39,593
  • 22
  • 116
  • 167
  • that gets rid of the error but if you change the colour it makes the canvas blank insted of changing the pattern colour – matt gaming Jul 23 '22 at 16:40