3

Have mercy, I'm a beginner.

I'm trying to write a very basic application to run 'chkdsk c:' and print out the output to a text box line by line. for each line I want a ttk.Progressbar to move a bit. I've seen similar questions answered here, but couldn't get them to work. I got this far:

from Tkinter import *
import ttk
from subprocess import Popen, PIPE

gui = Tk()

text = Text(gui)
lb = ttk.Label(text="Chkdsk")
prog = ttk.Progressbar(mode='indeterminate')

def chkdsk():
    proc = Popen(['chkdsk','c:'],stdout=PIPE)
    while True:
        line = proc.stdout.readline()
        if line != '':
            text.insert(INSERT, "\n")
            text.insert(END, line.rstrip())
            prog.step(1)
            gui.update()
        else:
            break

bt = ttk.Button(text="Chkdsk", command=chkdsk).grid(row=4, column=5)

text.grid(row=6, column= 5)
lb.grid(row=3, column=5)
prog.grid(row=7,column=5)
mainloop()

Ok, so when I run this .pyw script on an elevated command prompt(this is good for my purposes) - "python chkdsk.pyw" and initiate the chkdsk, it starts working, and then shortly thereafter becomes non responding.

I believe the problem has something to do with buffering?

Netanel
  • 55
  • 6
  • [see links in this comment](http://stackoverflow.com/questions/22627148/tkinter-subprocess-locking-gui-and-not-returning-stdout-to-text#comment34460372_22627148) – jfs Oct 09 '14 at 22:55
  • @J.F.Sebastian Thanks, I can easily change one line to make that work. but I can't understand 90% of it. – Netanel Oct 10 '14 at 16:51
  • If you have a specific question about the code; [ask](http://stackoverflow.com/questions/ask) – jfs Oct 10 '14 at 20:03

1 Answers1

0

readline is blocking. Use non-blocking read and the after-method.

Daniel
  • 42,087
  • 4
  • 55
  • 81