如何解决如何显示每个消息框有两个条件的两个消息框?
我是个初学者。
我想说的是,如果 label9 中的数字 >= 60 显示一个消息框说一件事,如果它的
def create_window():
new = Toplevel()
new.title('Lockdown Tracker')
new.geometry('950x500')
new.configure(bg="gray")
label2 = Label(new,text="Please answer the questions below.",font=('Helvetica 30 bold'),relief= RIDGE)
label2.place(rely=0)
label3 = Label(new,text = "Q1. Rate the severity of the economic situation in your country. (1-100) *",font = ("Arial",25))
label3.place(rely=0.1)
text3=Entry(new,width = "60")
text3.place(rely=0.15)
label4= Label(new,text="Q2. Rate the speed of vaccination in your country. (1-100) *",25))
label4.place(rely=0.21)
text4=Entry(new,width = "60")
text4.place(rely=0.26)
label5= Label(new,text="Q3. Rate how much the regulations are enforced and safety measures are taken. (1-100) *",25))
label5.place(rely=0.31)
text5=Entry(new,width = "60")
text5.place(rely=0.36)
label6= Label(new,text="Q4. What is the percentage of vaccinated people?(%) *",25))
label6.place(rely=0.41)
text6=Entry(new,width = "60")
text6.place(rely=0.46)
label7= Label(new,text="Q5. What is the ratio of positivity in the last week?(%) *",25))
label7.place(rely=0.51)
text7=Entry(new,width = "60")
text7.place(rely=0.56)
label8= Label(new,text="Q6. What is the percentage of active cases?(%) *",25))
label8.place(rely=0.61)
text8=Entry(new,width = "60")
text8.place(rely=0.66)
def cmd3():
label9 = Label(new,text = int(text3.get())/6 + int(text4.get())/6 + int(text5.get())/6 + int(text6.get())/6 + int(text7.get())/6 + int(text8.get())/6)
label9.place(rely = 0.85)
window.mainloop() ```
解决方法
是的,您将使用 if/else 语句。为了检查 label9
中文本的值,我添加了另一个变量 label9Text
。然后可以在 if/else 语句中使用它来比较它。根据值,显示不同的消息框。 (如果您不确定如何导入消息框,请在程序顶部添加 from tkinter import messagebox
。您可以根据需要的图标将 showinfo
更改为 showerror
或 showwarning
.)
def cmd3():
label9Text = int(text3.get())/6 + int(text4.get())/6 + int(text5.get())/6 + int(text6.get())/6 + int(text7.get())/6 + int(text8.get())/6
label9 = Label(new,text = label9Text)
label9.place(rely = 0.85)
if label9Text >= 60:
messagebox.showinfo("Title","Text for >=60")
else:
messagebox.showinfo("Title","Text for <60")
,
我认为这应该有效:
if label9["text"] >= 60:
messagebox.showinfo(window,"something")
else:
messagebox.showinfo(window,"something else")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。