小编Mad*_*wal的帖子

在 Python Tkinter 中,button.configure() 命令未在 while 循环内运行

我正在尝试根据 while 循环确定的值来配置按钮,turn该值由 while 循环确定game_over

while 循环干扰了 tkinter 的主循环。我似乎无法找到解决这个问题的方法。

这是代码。

from tkinter import *
connect = Toplevel()

col1 = Button(connect, width=10, height=4, text=" ")
col1.grid(row=0, column=1)

game_over = False
turn = 0

while not game_over:
    if turn == 0:
        col1.configure(bg="#FE6869")
        x=input("Enter something")
        if x=="yes":
            game_over=True
        else:
            continue   
    else:       
        col1.configure(bg="#FFFC82")
        x=input("Enter something")
        if x=="no":
            game_over=True
        else:
            continue
    turn += 1
    turn = turn % 2

connect.mainloop()
Run Code Online (Sandbox Code Playgroud)

python tkinter button while-loop

0
推荐指数
1
解决办法
52
查看次数

标签 统计

button ×1

python ×1

tkinter ×1

while-loop ×1