I have write this code:
from tkinter import * count = 0def Pick_Celeb(): for v in range(len(Celeb_Photos)): if (z.get() == v): print("You ordered "+Celeb_Names[z]) def click_button(): global count count += 1 print("You have clicked the button "+str(count)+" Times")def submit(): Username = Enter_Box.get() print("You have set your username to: "+Username) delete() Enter_Box.config(state=DISABLED)def delete(): Enter_Box.delete(0,END)def backspace(): Enter_Box.delete(len(Enter_Box.get())-1,END)def display(): if (Check_Button_Status.get()==1): print("You agree") else: print("You don't agree")def click(event): Enter_Box.delete(0,END) Window = Tk() # Instaniates an instance of a window z = IntVar()Elon_Musk_Photo = PhotoImage(file="Elon_Musk(50x28).png")Jeff_Bezoz_Photo = PhotoImage(file="Jeff_Bezoz(50x28).png")Mark_Zuckerberg_Photo = PhotoImage(file="Mark_Zuckerberg_Small(50x30).png")Celeb_Photos = [Elon_Musk_Photo, Jeff_Bezoz_Photo, Mark_Zuckerberg_Photo]Celeb_Names = ["Elon Musk", "Jeff Bezoz", "Mark Zuckerberg"]for Index in range(len(Celeb_Names)): radiobutton = Radiobutton(Window, text=Celeb_Names[Index], variable=z, value=Index, padx=25, font=("Impact",20), image=Celeb_Photos[Index], compound="right", width=250, command=Pick_Celeb) radiobutton.place(x=500, y=50+Index*45)Photo = PhotoImage(file="Pig2.png") Like_Button = PhotoImage(file="Like-Button2.png")Window.geometry("900x600") Window.title("The Ultimate GUI Program") Window.iconbitmap("AngryBird9.ico")button = Button(Window, text="Click me", command=click_button, font=("Comic Sans,",10,"bold"), fg="Red", bg="black", activeforeground="Red", activebackground="black", image=Like_Button, compound="bottom")button.place(x=50,y=50) Window.config(background="white")Label = Label(Window, text="You are using the best program ever!", font=("Arial",10,"bold"), fg="red", bg="white",relief=RAISED,bd=10, padx=10, pady=10,image=Photo, compound="bottom")Label.place(x=170,y=170) Enter_Box = Entry(Window,font=("Arial"),fg="Black",bg="Gray") Enter_Box.place(x=460,y=220)Submit_button = Button(Window, text="Submit", command=submit)Submit_button.place(x=700,y=220)Delete_button = Button(Window, text="Delete", command=delete)Delete_button.place(x=750,y=220)BackSpace_button = Button(Window, text="Backspace", command=backspace)BackSpace_button.place(x=795,y=220) Check_Button_Status = IntVar()Checkbox = Checkbutton(Window, text="I agree to the TOS", variable=Check_Button_Status, onvalue=1, offvalue=0, command=display)Checkbox.place(x=200,y=100) Enter_Box.insert(0,"Enter username")Enter_Box.bind("<Button-1>",click)Window.mainloop() To produce this GUI window:
https://i.stack.imgur.com/nl0S6.png
However when trying to click a Radio button I get this error:
"TypeError: list indices must be integers or slices, not IntVar"
What I can understand from this is that I need to somehow cast an IntVar value to a numerical value that can used as an indice for the list but I can not find anything anywhere that explains how to, so can I fix this or do I need to do this another way?