Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter
- import contextlib
- class TextIO:
- def __init__(self, text):
- self.text = text
- def write(self, msg):
- self.text.insert(tkinter.END, msg)
- def flush(self):
- pass
- def button_pressed():
- print("The button was pressed.")
- root = tkinter.Tk()
- text = tkinter.Text(root)
- text.pack()
- button = tkinter.Button(root, text="click me", command=button_pressed)
- button.pack()
- with contextlib.redirect_stdout(TextIO(text)):
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement