python - display a log file in real time with tkinter text field (python2.7) -


i trying write gui can display log file in real time (tail -f log). new line log file can printed out terminal, cannot loaded text field (line #). can 1 tell me why won't put text field?

from tkinter import * import os, time import tkfiledialog  class controller(object):     def __init__(self, master):         """ main interface:         master - top level window         """         self._master = master          frame1 = frame(self._master)         label = label(self._master, text="select log file")         label.pack(side=top)         currentlogfile = stringvar(self._master)         logfilelist = [f f in os.listdir('.') if os.path.isfile(f)]         currentlogfile.set(logfilelist[0])         chooselog = optionmenu(self._master, currentlogfile, *logfilelist, command = self.file_open)         chooselog.config(width = "300")         chooselog.pack(side=top)         self._master.config(menu=chooselog)         self._text=text(frame1, bg = 'black', fg = 'white')         self._text.pack(side = top,fill=both, expand = true,pady=20)         w = 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)         open(filename,'r') f:             loglines = follow(f)             line in loglines:                 #print line                 self._text.insert(end,line)  def follow(thefile):     thefile.seek(0,2)     while true:         line = thefile.readline()         if not line:             time.sleep(5)             continue         yield line                   if __name__ == "__main__":     root=tk()     c=controller(root)     root.title("log")     root.geometry("750x500")     root.mainloop() 


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -