The widget you're looking for is a ttk::progressbar
(Tcl) or tkinter.ttk.Progressbar
(Python). You'll need to decide whether to use it in determinate or indeterminate mode and stuff like that.
There's one key tricky thing about using a progress bar: you need to keep the event loop running while you're displaying it. This means you need to either put the work in a separate thread or call update
periodically. Both options have their tricky aspects:
- When using a separate worker thread, that thread must not touch the GUI at all. Instead, it has to send messages to the GUI thread asking it to do the update.
- When using periodic
update
calls (once every quarter second or so is usually enough) you need to be very careful to not recursively enter full event loop processing (see the TkDocs page on the event loop for a discussion). This often involves doing things like disabling buttons while the processing is going on.
Were you instead after a progress bar in a terminal, those are comparatively simple because you don't have to manage an event loop; the terminal itself will do that for you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…