在我的程序中,我使用 tkinter,问题在于单击提交按钮后函数内的 if else 条件。
from tkinter import *
main = Tk()
def show_answer():
Ans = int(num1.get())
if Ans>5 or Ans <10:
blank.config(text="this is between 5 and 10")
else:
blank.config(text="this is out of range")
Label(main, text = "Enter Num 1:").grid(row=0)
Label(main, text = "The Sum is:").grid(row=2)
num1 = Entry(main)
blank = Label(main,text="", width=25 )
num1.grid(row=0, column=1)
blank.grid(row=2, column=1)
Button(main, text='Quit', command=main.destroy).grid(row=4, column=0, sticky=W, pady=4)
Button(main, text='Show', command=show_answer).grid(row=4, column=1, sticky=W, pady=4)
main.mainloop()
您正在写
or
而不是 and
试试这个:
if 5 <= Ans <= 10: