python - 使窗口关闭特定值(python)

标签 python tkinter

我试图在单击按钮一定次数并选择两个单选按钮之一后关闭窗口。目前这是我的代码(至少是适用的部分):

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()

第四次按下下一个按钮后,无论是否选择其中一个单选按钮,都会销毁窗口。只有当其中之一发生时,才会发生这种情况。怎么了?

最佳答案

这是因为您在 next_slide_window2() 函数内使用变量的 get 函数引用 game_length.get 进行比较。

game_length.get 更改为 game_length.get(),以便使用 game_length 变量的值。

关于python - 使窗口关闭特定值(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55014209/

相关文章:

python - 删除一个数据框中同时也在另一个数据框中的所有行的最快/最Python式的方法是什么?

python - Altair 热图刻度文本

python - 如何仅标准化数据帧的一列,同时保持其他列不受影响?

枚举对象上的python dict函数

python - 将菜单中复选按钮的默认值设置为 True

python - 如何在 python 中触发和监听事件?

python - 为什么这个小部件位于菜单栏的顶部?

python - Tkinter Canvas 文本添加边框(轮廓)

python-3.x - 将 Web 浏览器窗口添加到 Tkinter 窗口