I am very new to python. I have developed a program using the GUI of python. My development is almost done but i am stuck with a point. I have designed my gui using Listbox to read data from a file and show it. All i need to add a scroll in it. I have to submit it in next 9hours so i am in very bad postion. After a detail searched in google i found some way and tried but i failed. So please help me with this. Code are given below..
from Tkinter import *
import tkFileDialog
import time
import threading
import os
import sys
class View(Listbox):
def __init__(self, master):
Listbox.__init__(self, master) #makes view class listbox
class Tc(threading.Thread):
def run(self):
numlines = 0
forLoopNumLines = 0
x = 0
file_log = open('/var/log/kern.log')
for line in file_log:
numlines += 1
#print "number of line outsie of while"
#print numlines
while 1>0:
c_numlines=0
file_log = open('/var/log/kern.log')
for line in file_log:
c_numlines += 1
if numlines<c_numlines and c.fl == 0:
#print "c_number of line inside if"
#print c_numlines
forLoopNumLines = c_numlines-numlines
#print "number of line difference"
#print forLoopNumLines
#print "number of lines"
#print c_numlines
numlines = c_numlines
file_log = open('/var/log/kern.log')
file_log_new = open('log.txt','w')
last_line = file_log.readlines()[-forLoopNumLines:]
file_log_new.writelines(last_line)
filenamelog = "log.txt"
file_log.close()
file_log_new.close()
os.system('beep -f 3100 -l 1')
with open(filenamelog,'r') as f:
for line in f:
c._Listbox.insert(END,line)
class Controller(object):
def __init__(self, master):
self._master = master
frame1 = Frame(self._master)
frame1.pack(side=TOP, fill=BOTH, padx=5,expand=True)
self._Listbox=View(frame1)
self._Listbox.pack(side = TOP,fill=BOTH, expand = True,pady=20)
self.button2 = Button(frame1, text="Monitor", command=self.start_t)
self.button2.pack(side=LEFT, padx=5, pady=10)
self.button = Button(frame1, text="Pause", command=self.pause_thread)
self.button.pack(side=BOTTOM, padx=10, pady=10)
self.button.place(x=91, y =662)
self.button1 = Button(frame1, text="Continue", command=self.continue_t)
self.button1.pack(side=BOTTOM, padx=10, pady=10)
self.button1.place(x=171, y =662)
self.button3 = Button(frame1, text="Exit", command=self.exit_main_prog)
self.button3.pack(side=BOTTOM, padx=10, pady=10)
self.button3.place(x=261, y =662)
self.t = Tc()
self.fl=0
def start_t(self):
c.t.start()
def pause_thread(self):
c.fl = 1
def continue_t(self):
c.fl=0
def exit_main_prog(self):
sys.exit()
if __name__ == "__main__":
root=Tk()
root.geometry("1000x700")
root.resizable(0,0)
root.title("Log monitoring system")
c=Controller(root)
root.mainloop()