Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import tkinter
  2. import contextlib
  3.  
  4. class TextIO:
  5. def __init__(self, text):
  6. self.text = text
  7. def write(self, msg):
  8. self.text.insert(tkinter.END, msg)
  9. def flush(self):
  10. pass
  11.  
  12. def button_pressed():
  13. print("The button was pressed.")
  14.  
  15. root = tkinter.Tk()
  16. text = tkinter.Text(root)
  17. text.pack()
  18.  
  19. button = tkinter.Button(root, text="click me", command=button_pressed)
  20. button.pack()
  21.  
  22. with contextlib.redirect_stdout(TextIO(text)):
  23. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement