Logscreen.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import tkinter as tk
  2. from tkinter.ttk import Progressbar
  3. import Log_handler
  4. class LogScreen(tk.Frame):
  5. def __init__(self, root):
  6. self.root = root
  7. tk.Frame.__init__(self, root)
  8. self.log_handler = Log_handler.get_log_handler()
  9. self.text = tk.Frame(self,relief="sunken",borderwidth=1)
  10. self.text.pack(expand=True,fill=tk.BOTH)
  11. self.y_scroll = tk.Scrollbar(self.text)
  12. self.y_scroll.pack(side="right", fill="y")
  13. self.x_scroll = tk.Scrollbar(self.text, orient='horizontal')
  14. self.x_scroll.pack(side="bottom", fill="x")
  15. self.textfield = tk.Listbox(self.text, yscrollcommand=self.y_scroll.set, xscrollcommand=self.x_scroll.set)
  16. self.textfield.pack(side="left",expand=True, fill=tk.BOTH)
  17. self.y_scroll.config(command=self.textfield.yview)
  18. self.x_scroll.config(command=self.textfield.xview)
  19. self.quit_button = tk.Button(self, text="Quit", command=self.close, height=2, width = 10)
  20. self.quit_button.pack(side="right", fill="both")
  21. self.refresh_button = tk.Button(self, text="Refresh", command=self.fill_textfield, height=2, width = 10)
  22. self.refresh_button.pack(side="right", fill="both")
  23. self.fill_textfield()
  24. root.bind('<Escape>', self.close)
  25. def update(self):
  26. if not self.root.winfo_exists():
  27. return
  28. def close(self):
  29. if self.root.winfo_exists():
  30. self.root.destroy()
  31. def fill_textfield(self):
  32. self.textfield.delete(0,"end")
  33. for element in self.log_handler.get_log_list():
  34. self.textfield.insert(tk.END, element)