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()

Your indention and line spacing is messed up post the code properly and explain what works and where you have problems.

What exactly are you trying to do? It is not obvious from the program.

There are other problems in addition to indentation:

while 1>0:

The above is an infinite loop that you never exit.

You open the file '/var/log/kern.log' at least 3 times without previously closing it.

You mix pack() and place() which produces unknown results. Start with a small snippet and test it (it is obvious from the indentation that this program has not been tested). Get that part running and then add more and test it, etc. Post back with specific questions when you run into a problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.