-1

How do I make this specific loading bar code also display percentages at the same time. Could someone also help me put it in a TKInter window, then close that specific TKInter window???

print 'LOADING'

toolbar_width = 40


for i in range(toolbar_width):
    time.sleep(0.1) # do real work here
    # update the bar
    sys.stdout.write("-")
    sys.stdout.flush()

sys.stdout.write("\n")
Sidsy
  • 161
  • 2
  • 3
  • 11
  • Stackoverflow isn't a code-writing service. Is there a specific part of the problem you are struggling with? – Bryan Oakley Oct 25 '15 at 12:02
  • Yes, as I always get the percentage before or after the dash loading bar, but never at the same time – Sidsy Oct 25 '15 at 12:16

1 Answers1

0

Based on your code i do not see the percentage printed anywhere.

How do you want to print it at the same time? and where?

I personally see multiple options:

  • use Tkinter and use different widgets either on top or next to each other and increase both values at the same time.
  • using the console output you could clear the console and print formatted strings based on your process (like "------70%--- " )

If you want to use tkinter you should first create your script, then try to run it and if you run into errors you can ask a SO Question with specific errors for specific problem sets.

As Bryan mentioned earlier, this is StackOverflow not some kind of "LetMeCodeThatForYou" platform. Nevertheless i will attach some pseudo-code as a hint what could be done.

What you could try in some tkinter code is something like:

import Tkinter as tk
class MyWidget(tk.Window):
    def __init__(self, *args, **kwargs):
        # [...] for real code there needs to be more in here...
        self.percentage=tk.StringVar()
        self.progressbarwidget=SomeWidget(self)
        self.progressbarwidget.grid()        
    def increase_counter(step=1):
        self.percentage.set("%s%%"%(int(self.percentage.get()[-1:])+step))
        self.progessbarwidget.configure(width=width+step)
        if self.percentage.get()=="100%":
            #destroy the window / widget / whatever here...
            self.destroy()
        else:
            self.after(1000, self.increase_counter)

using something like this in your application would update both at the same time, the percentage Value and the appearance of the widget.

Please note that this is only sample code, some kind of hint how a structure like you want it can be done.

Also have a look over here Python: Is it possible to create an tkinter label which has a dynamic string when a function is running in background?

Community
  • 1
  • 1
R4PH43L
  • 2,122
  • 3
  • 18
  • 30