I would like to print on a .txt or .log file everything that would be printed on the terminal especially the errors.
In this example I put an error when clicking the button and would like it to be captured and printed on the file.
In this case the error is known to occur when the button is clicked. But I would like any errors that may occur while using the program to be captured and printed to the file
import tkinter as tk
def on_click():
# this error is made specifically to explain what I would like to achieve
print(int("string"))
# Create the window
win = tk.Tk()
win.geometry("500x300")
win.title("window")
# Create the button
tk.Button(win, text="Button", command=on_click).pack()
if __name__ == "__main__":
win.mainloop()
this in the photo is an example of the error I would like to capture
