This is my code:
class TimeFrame(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.text = tk.Text(self, height=10, width=110)
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.text.yview)
self.text.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.text.pack(side="left", fill="both", expand=True)
def add_timestamp(self):
self.text.insert("end", time.ctime() + "\n")
self.text.see("end")
self.after(1000, self.add_timestamp)
class ButtonFrame(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.button = tk.Button(self, text="Start Time", command=self.start_time)
self.button.pack()
def start_time(self):
TimeFrame.add_timestamp()
if __name__ == "__main__":
root = tk.Tk()
time_frame = TimeFrame(root)
time_frame.pack(fill="both", expand=True, padx=10, pady=20)
button_frame = ButtonFrame(root)
button_frame.pack(fill="both", expand=True, pady=(0, 20))
root.mainloop()
I want that the add_timestamp()
function runs when the button is clicked.
Without an argument in TimeFrame.add_timestamp()
I get an error saying missing argument "self".
What do I need to write as an argument there that it is working properly?