Hello. I'm creating a layout converter using Python 3.6.4 and Tkinter.
Among other things, the GUI should have a progress bar that updates its value with each interaction of the conversion process, for example, every processed line of the file being converted, the progress bar should be updated.
The problem I am facing is that the program crashes while you are performing the conversion and the toolbar is not updated. The bar only refreshes at the end of the conversion operation.
The basic part of the script is this (I removed everything that is not relevant and left only the essentials to see where the problem is or where I'm going wrong):
import sys
from time import sleep
from tkinter import *
from tkinter.ttk import Progressbar
class Gui:
def __init__(self):
self.Window = Tk()
self.Window.geometry('{0}x{1}'.format(600, 400))
self.progress = StringVar()
self.progress.set(0)
self.progressBar = Progressbar(self.Window, maximum=100, orient=HORIZONTAL, variable=self.progress)
self.progressBar.grid(row=0, column=0, sticky=W + E)
self.startButton = Button(self.Window, text='Iniciar', command=self.start)
self.startButton.grid(row=0, column=2)
def start(self):
for t in range(0,100):
self.progress.set(t)
sleep(0.1)
def run(self):
self.Window.mainloop()
return 0
if __name__ == '__main__':
Gui = Gui()
sys.exit(Gui.run())
I am a beginner in Python but I have a long experience (fifteen years) with PHP and etc.