[030aeb]: / dosma / gui / gui_utils / console_output.py

Download this file

19 lines (15 with data), 569 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import logging
import sys
import tkinter as tk
class WidgetLogger(logging.StreamHandler):
def __init__(self, widget):
logging.Handler.__init__(self, sys.stdout)
self.setLevel(logging.INFO)
self.widget = widget
self.widget.config(state="disabled")
def emit(self, record):
self.widget.config(state="normal")
# Append message (record) to the widget
self.widget.insert(tk.END, self.format(record) + "\n")
self.widget.see(tk.END) # Scroll to the bottom
self.widget.config(state="disabled")