mardi 31 juillet 2018

My check in and out code using tkinter is not outputting the expected result

This code is expected to tell the user red or green and change the users label to red or green depending on whether they are check or out. To check in or out you type 1 - 4 (depending on the user) in the e entry widget. but this code just keeps all of the names red and just outputs "red" when it should be alternating.

import time
import csv
import tkinter
Users = ["1","2","3","4"]
UserDecode = ["Ben","Vicki","Steve","Sean"]
UserInOut = ["red","red","red","red"]
def login():
        Users = ["1","2","3","4"]
        UserDecode = ["Ben","Vicki","Steve","Sean"]
        UserInOut = ["red","red","red","red"]
        global e
        w = tkinter.Tk()
        root=tkinter.Frame(w)
        root.pack()
        root.destroy()
        root=tkinter.Frame(w)
        root.pack()
        for i in UserDecode:
                Num=UserDecode.index(i)
                tkinter.Label(root, text=i, fg=UserInOut[Num]).pack()
        e = tkinter.Entry(root, text="ID NUM")
        e.bind("<Return>", CheckIt)
        e.pack()
        w.mainloop()
def CheckIt(event):
        global e, Users, UserDecode, UserInOut
        In= e.get()
        e.delete(0, 'end')
        if In in Users:
                UserCheck = int(In)
                print("Found User: ", UserDecode[UserCheck - 1])
                if UserInOut[UserCheck - 1] == "red":
                        UserInOut[UserCheck - 1] == "green"
                        print(UserInOut[UserCheck - 1])
                elif UserInOut[UserCheck - 1] == "green":
                        UserInOut[UserCheck - 1] = "red"
                        print(UserInOut[UserCheck - 1])
                        print("                 ")
                        login()
                else:
                        print("no user found")
                        login()
login()

Aucun commentaire:

Enregistrer un commentaire