93 lines
2.4 KiB
Python
93 lines
2.4 KiB
Python
# Zeiterfassung
|
|
# UI Definitionen
|
|
|
|
import tkinter as tk
|
|
import locale
|
|
locale.setlocale(locale.LC_ALL, '')
|
|
|
|
from time import strftime
|
|
from definitions import app_title, app_version
|
|
|
|
# Pinpad
|
|
|
|
def win_pinpad():
|
|
|
|
def update_time():
|
|
string_time = strftime('%A, der %d.%m.%Y - %H:%M:%S')
|
|
nonlocal digital_clock
|
|
digital_clock.config(text=string_time)
|
|
digital_clock.after(1000, update_time)
|
|
|
|
root = tk.Tk()
|
|
root.title(app_title + " " + app_version)
|
|
root.eval('tk::PlaceWindow . center')
|
|
|
|
# Digital clock label configuration
|
|
digital_clock = tk.Label(root)
|
|
digital_clock.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
|
|
# Initial call to update_time function
|
|
update_time()
|
|
|
|
# Benutzernummer
|
|
def usernr_changed(UserNr):
|
|
nonlocal usernr
|
|
if len(str(usernr.get())) > 0:
|
|
buttons["OK"].configure(state="active")
|
|
else:
|
|
buttons["OK"].configure(state="disabled")
|
|
|
|
|
|
tk.Label(root, text="Benutzernummer:").grid(row=1, column=0)
|
|
UserNr = tk.StringVar()
|
|
UserNr.trace("w", lambda name, index, mode, UserNr=UserNr: usernr_changed(UserNr))
|
|
usernr = tk.Entry(root, width=10, textvariable=UserNr)
|
|
usernr.grid(row=1,column=1)
|
|
|
|
# Pinpad
|
|
|
|
def buttonPress(key):
|
|
|
|
nonlocal usernr
|
|
if type(key) is int:
|
|
if key < 10:
|
|
usernr.insert('end', str(key))
|
|
if key =="OK":
|
|
print("OK pressed")
|
|
if key == "<-":
|
|
usernr.delete(usernr.index("end") - 1 )
|
|
if len(usernr.get()) > 0:
|
|
buttons["OK"].configure(state="active")
|
|
else:
|
|
buttons["OK"].configure(state="disabled")
|
|
|
|
# Buttons definieren
|
|
button_width = 7
|
|
button_height = 3
|
|
pinframe = tk.Frame(root)
|
|
pinframe.grid(row=2, column=0, columnspan=3, padx=10, pady=10)
|
|
buttons = { }
|
|
|
|
keys = [
|
|
[ 1, 2, 3],
|
|
[ 4, 5, 6],
|
|
[ 7, 8, 9],
|
|
[ "<-", 0, "OK"]
|
|
]
|
|
|
|
for y, row in enumerate(keys, 1):
|
|
for x, key in enumerate(row):
|
|
button = tk.Button(pinframe, width=button_width, height=button_height, text=key, command=lambda key=key: buttonPress(key))
|
|
button.grid(row=y, column=x)
|
|
buttons[key] = button
|
|
|
|
buttons["OK"].configure(state="disabled")
|
|
|
|
usernr.focus_set()
|
|
|
|
# Tkinter main loop
|
|
|
|
root.mainloop()
|
|
|
|
def win_userselection():
|
|
|