0% found this document useful (0 votes)
6 views1 page

Log Files

Uploaded by

Tito Miguelin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Log Files

Uploaded by

Tito Miguelin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import tkinter as tk

from tkinter import ttk


import os, time
from tkinter import filedialog

class Controller(object):
def __init__(self, master):
""" Main interface:
master - the top level window
"""
self._master = master

frame1 = ttk.Frame(self._master)
label = ttk.Label(self._master, text="Select a Log File")
label.pack(side='top')
currentLogfile = tk.StringVar(self._master)
LogfileList = [f for f in os.listdir('C:\\Users\\miguel_hernandez\\
VS_Code') if os.path.isfile(f)]
currentLogfile.set(LogfileList[0])
chooseLog = ttk.OptionMenu(self._master, currentLogfile, *LogfileList,
command = self.file_open)
chooseLog.config(width = "300")
chooseLog.pack(side='top')
self._master.config(menu=chooseLog)
self._Text=tk.Text(frame1)
self._Text.pack(side = 'top',fill='both', expand = True,pady=20)
w = ttk.Scrollbar(self._Text)
w.pack(side='right', fill='y')
frame1.pack(side='top', fill='both', padx=5,expand=True)

def file_open(self,filename):
#clear text field
self._Text.delete('1.0', 'end')
with open(filename,'r') as f:
loglines = self.follow(f)
for line in loglines:
#print line
self._Text.insert('end',line)

def follow(self,thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(5)
continue
yield line

if __name__ == "__main__":
root=tk.Tk()
c=Controller(root)
root.title("log")
root.geometry("750x500")
root.mainloop()

You might also like