Basically I am trying to implement the tail function from ubuntu into a python tkinter button. The tail code works fine but only when I try to implement it into tkinter I am running into the problem of the entire gui freezing. There are several approaches I can take to fix this problem however I am wondering what would be the easiest and fastest way to approach this. Here is my code so far:
#gui code
from tkinter import *
from tkinter import filedialog
from tkinter import Tk, Button
from subprocess import Popen
import tkinter
import os
import time
master = Tk()
root = tkinter.Tk()
root.attributes("-topmost",True)
master.withdraw()
root.lift()
def userpass():
os.startfile('config.ini')
def follow(thefile):
thefile.seek(0,2) # Go to the end of the file
while True:
line = thefile.readline()
if not line:
time.sleep(1) # Sleep briefly
continue
yield line
def crap(tex):
loglines = follow(open("jessica.gw2.log"))
for line in loglines:
#print(line)
tex.insert(tkinter.END, line)
tex.see(tkinter.END)
def cbc(tex):
return lambda : crap(tex)
x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 1.1
y = (root.winfo_screenheight() - root.winfo_reqheight()) / 20
root.geometry("+%d+%d" % (x, y))
tex = tkinter.Text(root)
tex.pack(side=tkinter.BOTTOM)
b = Button(root, text="Set your Options ", command=userpass)
o = Button(root, text="Press to view logs", command = cbc(tex))
b.pack()
o.pack()
mainloop()
Changed around my function. Only had to make some slight modifications. I got rid of crap, cbc and the follow functions and then I changed this button
o = Button(root, text="Start monitoring Log file", command = viewlogfile)
so that it calls this function that I added
def viewlogfile():
f = open('insertfilenamehere', "r")
text = f.read()
tex.insert(tkinter.END, text)
tex.see(tkinter.END)
root.after(3000,viewlogfile)
and then left everything else the same