# Import Modulefromtkinterimport*# Create Objectroot=Tk()# Add Titleroot.title('On/Off Switch!')# Add Geometryroot.geometry("500x300")# Keep track of the button state on/off#global is_onis_on=True# Create Labelmy_label=Label(root,text="The Switch Is On!",fg="green",font=("Helvetica",32))my_label.pack(pady=20)# Define our switch functiondefswitch():globalis_on# Determine is on or offifis_on:on_button.config(image=off)my_label.config(text="The Switch is Off",fg="grey")is_on=Falseelse:on_button.config(image=on)my_label.config(text="The Switch is On",fg="green")is_on=True# Define Our Imageson=PhotoImage(file="on.png")off=PhotoImage(file="off.png")# Create A Buttonon_button=Button(root,image=on,bd=0,command=switch)on_button.pack(pady=50)# Execute Tkinterroot.mainloop()