try:
#Python 2
import Tkinter as tk
except ImportError:
#Python 3
import tkinter as tk
def flip_switch(canv_obj, btn_text):
if btn_text == 'on':
canv_obj.config(bg="#F1F584")
else:
canv_obj.config(bg="#000000")
main_window = tk.Tk()
light = tk.Canvas(main_window, bg="#000000", width=100, height=50)
light.pack()
on_btn = tk.Button(main_window, text="ON", command=flip_switch(light, 'on'))
on_btn.pack()
off_btn = tk.Button(main_window, text="OFF", command=flip_switch(light, 'off'))
off_btn.pack()
main_window.mainloop()
This little code acts as a light switch application but when the ON button is pressed, nothing happens -not even the error messages. Please correct me where I had gone wrong.