2016-10-25 1 views
-3

Ich versuche, den Index zu verwenden und die x und y Arrays miteinander zu kombinieren, so dass sie übereinstimmen. Sie scheinen jedoch nicht zu funktionieren.So erstellen Sie eine "messagebox.askquestion" mit Array-Variablen

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() 
+0

Wenn Sie den Code in Ihre Frage kopieren, erhalten Sie wahrscheinlich eine schnellere Antwort –

+0

Bitte fügen Sie den Code als Text in die Frage selbst ein, anstatt nur auf ein Bild davon zu verlinken. – EJoshuaS

Antwort

1

Ihre if Logik Aussage ist jetzt fehlerhaft.

Anstatt Index von 0, möchten Sie Index der Eingabe erhalten.

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

Und statt das erste Element des x vergleichen, sollten Sie überprüfen, ob x Eingabe des Benutzers enthält.

if p in x: 

Zusätzlich gibt es einen Tippfehler in Ihrer askquestion Linie. Option message geschrieben mit zwei s nicht drei.

Verwandte Themen