Jun-07-2024, 11:26 AM
Please post code using the bbtags. Makes it easier to help.
Is this what you are trying for?
Added a try block
Is this what you are trying for?
Added a try block
import tkinter as tk from tkinter import ttk from tkinter.messagebox import showinfo, showerror from datetime import datetime # root window root = tk.Tk() root.geometry("300x200") root.resizable(False, False) root.title('Time Clock') # store StartofWork address and EndofWork StartofWork = tk.StringVar() EndofWork = tk.StringVar() def login_clicked(): """ callback when the login button clicked """ WorkStart = StartofWork.get() tdelta = timediff() if tdelta: """ msg = f'Start of Shift: {StartofWork.get()} and End of Shift: {EndofWork.get()}' """ msg = f'Total Hours: {tdelta}' showinfo( title='Time Calculated', message=msg ) def timediff(): WorkStart = StartofWork.get() """StartTime = input("Enter Start Time in HH:MM\n") """ print("This is WorkStart", WorkStart) print("This is EndofWork", EndofWork.get()) FMT = '%H:%M' try: tdelta = datetime.strptime(EndofWork.get(), FMT) - datetime.strptime(StartofWork.get(), FMT) return tdelta except ValueError: showerror('Error!', 'Time format is not correct.') # Sign in frame signin = ttk.Frame(root) signin.pack(padx=10, pady=10, fill='x', expand=True) # StartofWork StartofWork_label = ttk.Label(signin, text="Clock In:") StartofWork_label.pack(fill='x', expand=True) StartofWork_entry = ttk.Entry(signin, textvariable=StartofWork) StartofWork_entry.pack(fill='x', expand=True) StartofWork_entry.focus() # EndofWork password_label = ttk.Label(signin, text="Clock Out:") password_label.pack(fill='x', expand=True) password_entry = ttk.Entry(signin, textvariable=EndofWork) password_entry.pack(fill='x', expand=True) # login button login_button = ttk.Button(signin, text="Calculate Time", command=login_clicked) login_button.pack(fill='x', expand=True, pady=10) root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags