Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.4 kB
2
Indexable
Never
class AttendanceApp:
    def __init__(self, root):
        # Existing code...
        self.entries = {}  # Initialize entries dictionary

        # Add a label for the timestamp
        self.labels.append("Timestamp")  # Add "Timestamp" to the list of labels
        for idx, label in enumerate(self.labels):
            if idx < len(self.labels):  # Check if the index is within the range of labels list
                tk.Label(root, text=label).grid(row=0, column=idx)
                if label == "Timestamp":  # If the label is "Timestamp", create an entry for it
                    self.timestamp_entry = tk.Entry(root)
                    self.timestamp_entry.grid(row=1, column=idx)
                    self.update_timestamp()  # Initialize timestamp entry with current date and time
                else:  # For other labels, create normal entry widgets
                    entry = tk.Entry(root)
                    entry.grid(row=1, column=idx)
                    entry.bind('<Return>', self.add_entry)  # Bind Enter key to add_entry function
                    self.entries[label] = entry

    def update_timestamp(self):
        # Update timestamp entry with current date and time
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.timestamp_entry.delete(0, tk.END)
        self.timestamp_entry.insert(0, current_time)
Leave a Comment