Ich mache gerade einen Vokabeltrainer, habe aber ein problem dabei.
So sieht derzeit der code aus:
Code: Alles auswählen
#!/usr/bin/python
import sys, re
from Tkinter import *
from time import *
global a
a = 0
def file_to_dict(name):
f = file(name)
c = f.read()
f.close()
global vokabel
vokabel = dict([(x[1],x[2].strip('"').strip())
for x in re.findall('((\w+)\s*=[ \t\f\v]*(("[^"]*")|(\S*))[^\n]*\n)',c)])
return vokabel
def ende():
sys.exit()
def get_input():
global b,c
global eingabe
b,c = 0,1
eingabe = entry.get()
if eingabe == voks[a][c]:
label2["text"] = "rischtisch"
ergebnis = 1
else:
label2["text"] = "leider falsch"
sleep(0.5)
print eingabe
print a,b,c
a=+1
label1["text"] = voks[a][b]
root = Tk()
label1 = Label(root, width=50, bg="white", fg="blue")
entry = Entry(root, width=50, bg="white", fg="black")
button1 = Button(root, text="OK", command = get_input)
button2 = Button(root, text="Exit", command = ende)
label2 = Label(root, width=50, bg="white", fg="blue")
label1.pack()
entry.pack()
label2.pack()
button1.pack()
button2.pack()
file_to_dict('vokabel.txt')
voks = vokabel.items()
label1["text"] = voks[0][0]
line 30, in get_input
if eingabe == voks[a][c]:
UnboundLocalError: local variable 'a' referenced before assignment
Ich habe die variable 'a' schon gleich am Anfang global definiert, also sollte sie ja beim Aufruf bekannt sein.
Kann mir da jemand weiterhelfen?[/quote]