#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    52
    Rep Power
    13

    Question Updating contents of file


    I have the collowing code for a GUI function:

    Code:
    def viewHist(self):
            newWin = Toplevel()
            newWin.title('History')
            scrollbar = Scrollbar(newWin, orient=VERTICAL)
            list = Listbox(newWin, yscrollcommand=scrollbar.set, width=45)
            scrollbar.config(command=list.yview)
            scrollbar.pack(side=RIGHT, fill=Y)
            log = file('calcs.log','r')
            rLog = log.readlines()
            log.close()
            for line in rLog:
                line = line.strip('\n')
                list.insert(END, line)
            list.pack()
            QB = Button(newWin, text='Close', command=newWin.destroy)
            QB.pack()
    I redirected the stdout stream to the calcs.log file. When a user clicks certain buttons, it prints it into the file via the output stream. However, the only way to get an updated history is to restart the program. How can I reload the file and update the listbox when a user clicks the View History button? Thanks.
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Basically you need a seperate update method for your list as strings are written to the file.

    grim
    Last edited by Grim Archon; October 4th, 2004 at 04:48 AM.

IMN logo majestic logo threadwatch logo seochat tools logo