First of all, thank you for reading my problem.
I wanted to create a program that creates a photo print button when a desired animal is selected with a radio button in the Windows interface, and prints a photo with the button.
It seems that the value is stored in the integer variable var by the radio button option, so I called vote_animal, the photo output button function first.
def vote_animal():
button1 = Button(window, text = "Picture", font = (5), fg = "black", command = show_animal)
button1.place(x = xPos, y = yPos)
#main code
var = IntVar()
dogRB = Radiobutton(window, text = "Dog", variable = var, value = 1, command = vote_animal)
catRB = Radiobutton(window, text = "Cat", variable = var, value = 2, command = vote_animal)
rabbitRB = Radiobutton(window, text = "Rabbit", variable = var, value = 3, command = vote_animal)
dogRB.pack()
catRB.pack()
rabbitRB.pack()
Then I believed that when the print photo button was clicked, the show_animal function would be called and the function would print the picture according to the var variable.
def show_animal():
if var.get() == 1:
photo = PhotoImage(file = "C:/picture/"+animalList[var.get()-1])
label2.configure(image = photo)
label2.pack()
elif var.get() == 2:
photo = PhotoImage(file = "C:/picture/"+animalList[var.get()-1])
label2.configure(image = photo)
label2.pack()
else :
photo = PhotoImage(file = "C:/picture/"+animalList[var.get()-1])
label2.configure(image = photo)
label2.pack()
Oh, for reference, the last path of the photo is implemented as animalList.
animalList=["dog.gif", "cat.gif", "rabbit.gif"]
Anyway, if I make the code like this, the picture is not printed even though there are no errors. So, I want to ask if the value of var does not apply to the show_animal function, or if there is another problem.
In case you don't know, I've put the code on github. Github URL: https://github.com/baecci/For_Stackoverflow
The first question may be a bit messy, but I would appreciate your kind answer.