diff --git a/__pycache__/definitions.cpython-311.pyc b/__pycache__/definitions.cpython-311.pyc index 5c90a03..29fae7f 100644 Binary files a/__pycache__/definitions.cpython-311.pyc and b/__pycache__/definitions.cpython-311.pyc differ diff --git a/__pycache__/users.cpython-311.pyc b/__pycache__/users.cpython-311.pyc new file mode 100644 index 0000000..1fb4698 Binary files /dev/null and b/__pycache__/users.cpython-311.pyc differ diff --git a/ui.py b/ui.py index ea4b0a8..4cfebe5 100644 --- a/ui.py +++ b/ui.py @@ -10,83 +10,99 @@ from definitions import app_title, app_version # Pinpad -def win_pinpad(): +class win_pinpad(tk.Toplevel): + def __init__(self, parent): + super().__init__(parent) - 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) + 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') + self.title(app_title + " " + app_version) - # 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() + # Digital clock label configuration + digital_clock = tk.Label(self) + 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") + # 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) + tk.Label(self, 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(self, width=10, textvariable=UserNr) + usernr.grid(row=1,column=1) - # Pinpad + # Pinpad - def buttonPress(key): + 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") + 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 = { } + # Buttons definieren + button_width = 7 + button_height = 3 + pinframe = tk.Frame(self) + 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"] - ] + 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 + 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") + buttons["OK"].configure(state="disabled") - usernr.focus_set() + usernr.focus_set() - # Tkinter main loop +class mainwindow(tk.Tk): + def __init__(self): + super().__init__() - root.mainloop() + self.geometry('300x200') + self.title('Main Window') + + # place a button on the root window + tk.Button(self, + text='Login Window', + command=self.open_window).pack(expand=True) + + def open_window(self): + window = win_pinpad(self) + window.grab_set() + + +if __name__ == "__main__": + app = mainwindow() + app.mainloop() -def win_userselection():