I am using python to make an employee name log that has 6 rows for new names to be entered. If there is no name left entered into the Entry box and it's left saying 'Enter Employee Name', I want to ignore it and not write it to a file.
Currently the way I have things it just prints if the condition is met and it kind of works but seems long. Is there a way to not include an Entry variable if it's not equal to 'Enter Employee Name'?
from tkinter import *
from datetime import *
import time
# define GUI
root = Tk()
root.title("Make Communication Record")
root.geometry("550x775")
# Time Stamp Label
day = datetime.today()
hour = time.strftime("%H")
minute = time.strftime("%M")
sec = time.strftime("%S")
f_daydisplay = day.strftime("%A - %B %d, %Y ")
t = f_daydisplay + " " + hour + ":" + minute + ":" + sec
#Refresh clock for time stamp label
def clock():
day = datetime.today()
f_daydisplay = day.strftime("%A - %B %d, %Y at ")
hour = time.strftime("%H")
minute = time.strftime("%M")
sec = time.strftime("%S")
timelab.config(text=f_daydisplay+hour + ":" + minute + ":" + sec)
timelab.after(1000, clock)
#Time stamp label
timelab = Label(root, text="")
timelab.grid(row=13, columnspan=4)
clock()
# Button Actions
def onclick(args):
# If submit clicked
if args == 1:
one = nameone.get()
two = nametwo.get()
three = namethree.get()
four = namefour.get()
five = namefive.get()
six = namesix.get()
if (one != 'Enter Employee Name' and two != 'Enter Employee Name' and three != 'Enter Employee Name' and four != 'Enter Employee Name' and five != 'Enter Employee Name' and six != 'Enter Employee Name'):
print('it worked all')
elif(one != 'Enter Employee Name' and two != 'Enter Employee Name' and three != 'Enter Employee Name' and four != 'Enter Employee Name' and five != 'Enter Employee Name'):
print('it worked 4')
elif(one != 'Enter Employee Name' and two != 'Enter Employee Name' and three != 'Enter Employee Name' and four != 'Enter Employee Name'):
print('it worked 3')
elif(one != 'Enter Employee Name' and two != 'Enter Employee Name' and three != 'Enter Employee Name'):
print('it worked 2')
elif(one != 'Enter Employee Name' and two != 'Enter Employee Name'):
print('it worked 1')
elif(str(one) != 'Enter Employee Name'):
print('it worked 0')
# if reset button clicked
if args == 2:
namea.insert(0, 'Enter Employee Name')
nameb.insert(0, 'Enter Employee Name')
namec.insert(0, 'Enter Employee Name')
named.insert(0, 'Enter Employee Name')
namee.insert(0, 'Enter Employee Name')
namef.insert(0, 'Enter Employee Name')
# Name Entry
nameone = StringVar()
namea = Entry(root, width=30, borderwidth=5, textvariable=nameone)
namea.grid(row=2, column=0, columnspan=1, padx=10, pady=10)
namea.insert(0, "Enter Employee Name")
nametwo = StringVar()
nameb = Entry(root, width=30, borderwidth=5, textvariable=nametwo)
nameb.grid(row=3, column=0, columnspan=1, padx=10, pady=10)
nameb.insert(0, "Enter Employee Name")
namethree = StringVar()
namec = Entry(root, width=30, borderwidth=5, textvariable=namethree)
namec.grid(row=4, column=0, columnspan=1, padx=10, pady=10)
namec.insert(0, "Enter Employee Name")
namefour = StringVar()
named = Entry(root, width=30, borderwidth=5, textvariable=namefour)
named.grid(row=5, column=0, columnspan=1, padx=10, pady=10)
named.insert(0, "Enter Employee Name")
namefive = StringVar()
namee = Entry(root, width=30, borderwidth=5, textvariable=namefive)
namee.grid(row=6, column=0, columnspan=1, padx=10, pady=10)
namee.insert(0, "Enter Employee Name")
namesix = StringVar()
namef = Entry(root, width=30, borderwidth=5, textvariable=namesix)
namef.grid(row=7, column=0, columnspan=1, padx=10, pady=10)
namef.insert(0, "Enter Employee Name")
#Buttons
btn1 = Button(root, text="Submit", width=20, command=lambda: onclick(1))
btn1.grid(row=12, column=0, padx=10, pady=10)
btn2 = Button(root, text="Reset Fields",
width=20, command=lambda: onclick(2))
btn2.grid(row=12, column=2, padx=10, pady=10)
root.mainloop()