Reputation: 25
I am trying to make a window close out after a button is clicked a certain amount of times and one of the two radio buttons are selected. Currently this is my code (at least the bit that applies):
from tkinter import *
slide=1
window2=Tk()
window2.title("Select Game Length")
window2.geometry('1600x800+0+0')
def next_slide_window2():
global slide
slide += 1
if slide==1:
window2_bg.config(image=intro1)
elif slide==2:
window2_bg.config(image=intro2)
elif slide==3:
window2_bg.config(image=intro3)
game_length_select_btn1.place(x=390, y=350)
game_length_select_btn2.place(x=790, y=350)
elif slide>=4 and game_length.get != 0:
window2.destroy()
best_of_3 = PhotoImage(file="bestof3.png")
best_of_5 = PhotoImage(file="bestof5.png")
intro1 = PhotoImage(file="window2_intro1.png")
intro2 = PhotoImage(file="window2_intro2.png")
intro3 = PhotoImage(file="window2_intro3.png")
next = PhotoImage(file="next.png")
window2_bg=Label(window2,image=intro1)
window2_bg.place(y=50, x=500) #at school, 50, 690; at home, 50, 500
next_button=Button(window2, image=next, command=next_slide_window2)
next_button.place(y=650, x=700) #at school, 800, 900; at home 650, 700
game_length=IntVar()
game_length.set(0)
game_length_select_btn1= Radiobutton(window2, image=best_of_3,
variable=game_length, value=3, command=game_length_select)
game_length_select_btn2= Radiobutton(window2, image=best_of_5,
variable=game_length, value=5, command=game_length_select)
window2.mainloop()
After the next button is pressed for the fourth time, it destroys the window whether or not one of the radio buttons is selected. This should only be happening if one of them are. What's wrong?
Upvotes: 1
Views: 43
Reputation: 47093
It is because you are using the variable's get
function reference game_length.get
in comparison inside next_slide_window2()
function.
Change game_length.get
to game_length.get()
so that you are using the value of game_length
variable.
Upvotes: 1