【问题标题】:My function's if statement is not working [duplicate]我函数的 if 语句不起作用 [重复]
【发布时间】:2023-01-23 00:37:58
【问题描述】:
#Gather Input from User - Moves

from tkinter import *
import tkinter.messagebox

main = Tk()

Label(main, text="Which red checkers piece do you want to move?").grid(row=0)
Label(main, text="Where do you want to move this piece?").grid(row=1)

piece = Entry(main)
move = Entry(main)

piece.grid(row=0,column=1)
move.grid(row=1,column=1)


def move_piece():
if piece == "A2" or "a2":
    if move == "B3" or "b3":
        cir1.move(75,75)

Button(main,text='Quit',command=main.destroy).grid(row=4,column=0,sticky=W,pady=4)
Button(main,text='Show',command=move_piece).grid(row=4,column=1,sticky=W,pady=4)


mainloop()

即使 move 和 piece 不是 a2 或 b3,我的代码仍然有效,有人知道为什么吗?

【问题讨论】:

  • 缺少缩进?和if (piece == 'A2') or (piece == 'a2'): ...

标签: python if-statement tkinter


【解决方案1】:

在函数冒号后按回车键,我想你忘了为函数中的 if 语句添加一些空间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 2018-08-28
    • 2012-11-30
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    相关资源
    最近更新 更多