【问题标题】:How to make a "messagebox.askquestion" using array variables如何使用数组变量制作“messagebox.askquestion”
【发布时间】:2016-10-25 00:02:45
【问题描述】:

我正在尝试使用索引并组合 xy 数组,以便它们对应。但是,它们似乎不起作用。

from tkinter import *    
from tkinter import messagebox

x = ['screen','speakers','earphone jack','button','switch off','storage']    
y = ['is the screen cracked','have the speakers been in conatct with water','has the earphone jack been in contact with water','is your button broken','is your battery older than 2 years','have you deleted enough data to allow more space']

solutions = ['go to the nearest phone store and get direct help','change your screen','put your phone in uncooked rice overnight and check in the morning','change your phone battery','delete enough data to allow you to download whatever you need']

**def problem1_1():**    
    i =  ' '.join(x)
    i.split(' ')
    p = problem1.get()
    if p == x[0] :
        messagebox.askquestion(title = "screen", messsage =y[x.index(0)])
        return**

myGui = Tk()    
problem1 = StringVar()    
myGui.geometry("500x500+200+200")   
myGui.title("troubleshooting system")  
myheader1 = Label(text = "Welcome To the Phone Troubleshooting System").pack()    
header2 = Label(text = "What seems to be the issue with  your phone? Is it an issue with your : screen, speakers, button,earphone jack, battery or storage",fg = 'blue',bg = 'yellow').pack()   
ientry = Entry(textvariable = problem1).pack()    
OkButton = Button(text = 'OK', command = problem1_1).pack()    
myGui.mainloop()

【问题讨论】:

  • 如果您将代码复制到您的问题中,您可能会得到更快的答案
  • 请将代码作为文本包含在问题本身中,而不仅仅是链接到它的图片。

标签: python-3.x tkinter


【解决方案1】:

您的if 语句的逻辑现在有缺陷。

您想要获取输入的索引,而不是索引 0。

p = problem1.get().lower() 
y[x.index(p)]

而不是比较x的第一项,你应该检查x是否包含用户的输入。

if p in x:

此外,您的askquestion 行中有一个错字。选项message 拼写为两个s 而不是三个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多