-1

Problem

When I run the program, I have sfc / scannow triggered and the progress bar does not appear, but only the program freezes until sfc scannow finishes its work.

Image - https://i.stack.imgur.com/Ei24y.jpg

I tried to change their places, but does not work

Function sfcScannow

def sfcScannow(event):

sfcWindow = Toplevel()
sfcWindow.title("Сканирование системы")
sfcWindow.minsize(350,480)
sfcWindow.maxsize(350,480)
sfcWindow['bg'] = '#fff2fe'

pb = ttk.Progressbar(sfcWindow, length=300, mode ="indeterminate")
msg = Label(sfcWindow, width=30, height=4, fg="#691962", relief="ridge", font="Intro 15", text="Начато сканирование")
msg2 = Label(sfcWindow, width=30, height=3, fg="#691962", relief="ridge", font="Intro 13", text="About UsefulTech.")
msg3 = Button(sfcWindow, width=30, height=3, fg="#691962", relief="ridge", font="Intro 16", text="Информация")

def InformSFC(event):
    mb.askyesno(title="Информация", message="Данная функция отвечает за проверку системных файлов, используя функцию Windows 'sfc /scannow'. Процесс может занимать более 20 минут и шкала процесса, не точно расчитана. Лучше ждать > 30 минут")

msg3.bind("<Button-1>", InformSFC)

msg.pack()
msg2.pack()
msg3.pack()
pb.pack(side="bottom")
pb.start()
os.system("sfc /scannow")

During the test, the progressbar should work, and after the test is completed, it should stop

  • I'm a bit confused, it looks like you make an async call to your popup box explaining what the program does, but then call os.system() to run the code that you want to be async. Try putting the os.system call into an async function and maybe read the output to get progress, because if I remember correct SFC doesn't give a time progress, just a 15% done, which means it jumps from 1 - 13 in a few seconds, but from 13-40 in a few minutes or days; meaning your best chance would probably just show the current % done, right? – Steve Byrne Dec 29 '18 at 03:58
  • I am new and do not quite understand in async . Can you explain in more detail what it means to "place an async function"? – A. Chernykh Dec 29 '18 at 04:04
  • 1
    *"the program freezes"*: Read about [tkinter-how-to-use-threads-to-preventing-main-event-loop-from-freezing](https://stackoverflow.com/questions/16745507/tkinter-how-to-use-threads-to-preventing-main-event-loop-from-freezing) – stovfl Dec 29 '18 at 04:12
  • It looks like you've got if figured out, at least enough to work, but generally speaking Async is a way to run multiple lines of code "at the same time" I put that in quote because that's not exactly what it does, but close enough. Basically it starts another thread to execute code on while allowing the thread that called it to continue executing code, such as being able to move or update the GUI. – Steve Byrne Dec 29 '18 at 05:20

1 Answers1

0

Answer

def sfcscannow():
        os.system("sfc /scannow")
    def prb():
        pb.pack(side="bottom")
        pb.start()  
    def StartScan(event):
        mb.askyesno(title="Информация", message="Проверка начата")
        t1 = threading.Thread(target=prb)
        t2 = threading.Thread(target=sfcscannow)
        t1.start()
        t2.start()