tkinter if else 相关的输入和输出问题

问题描述 投票:0回答:1

在我的程序中,我使用 tkinter,问题在于单击提交按钮后函数内的 if else 条件。

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()
python if-statement tkinter label tkinter-entry
1个回答
0
投票

您正在写

or
而不是
and
试试这个:

if 5 <= Ans <= 10:
© www.soinside.com 2019 - 2024. All rights reserved.