Sep-16-2021, 01:29 PM
Your problem is coming from line 15. You probably want a button instead of a text widget since you're trying to give it a command to execute. That being said, in tkinter you can't assign a function to a command that requires arguments so you may want to make the variable index a global. Also, you can't include parentheses when assigning a function to a command. Here is the working code but you may want to separate the button and the first text widget.
from tkinter import * root = Tk() root.geometry("200x400") root.title("Rainbow") codes = ['#FF0000', '#FFA500', '#FFFF00', '#008800', '#0000FF', '#000080', '#4B0082'] colours = ["red", "orange", "yellow", "green", "light blue", "blue", "violet"] index = 0 def chang_text(): colour_name.config(text=colours[index]) colour_code.config(text=codes[index]) colour_name = Button(font='Arial, 14', bg='#ffffff', width=20, height=2, command=chang_text) colour_name.pack(padx=5) colour_code = Label(font='Arial, 14', bg='#ffffff', width=20, height=2) colour_code.pack(padx=5) root.mainloop()