python - 如何显示两个消息框,每个消息框有两个条件?
问题描述
我是一个初学者。
我想说,如果 label9 >= 60 中的数字显示一个消息框说一件事,如果它 <60 我希望它显示一个不同的消息框说不同的事情。我使用 if/else/elif 语句还是什么?
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) *", font = ("Arial", 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) *", font = ("Arial", 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?(%) *", font = ("Arial", 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?(%) *", font = ("Arial", 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?(%) *", font = ("Arial", 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 label9["text"] >= 60:
messagebox.showinfo(window, "something")
else:
messagebox.showinfo(window, "something else")
推荐阅读
- python-2.7 - 使用数据框在 pyspark 中展开具有嵌套列表的列
- html - :在锚点上悬停过渡
- ios - SpriteKit 库 BUG:电池消耗(能量影响高/非常高)[解决方法]
- android - Andoridx Room rx 问题
- angular - firestore 与他的孩子一起获取文件
- android - IntentService 不受模拟器上睡眠或打瞌睡的影响
- python - 问题:前台的 PyQt5 QMessageBox
- node.js - 如何忽略 .csv 文件中的前 5 行,以便我可以将数据插入 postgresql DB
- php - 如何将特色图像添加到自定义 WordPress API 端点?
- node.js - 如何将使用 Node.js 和“ng new”命令创建的 Angular 应用程序导入 Spring Boot 应用程序?