I have this string that act’s like a progress bar
etichetta_download_mp3["text"] = 'r' + 'Download : %s%s%.2f%% ' % ('█' * int(size * 20 / contentsize), '' * (20 - int(size * 20 / contentsize)), float(size / contentsize * 100))
Please could you explain me how to add a single space like " "
in the red arrow? Like end of the bar, space and then the 100 % percentage, because in my image they are too closed, probably it’s an easy task but i can’t understand how to do it … thanks!
Advertisement
Answer
One format that should work is probably 'Download : %s%s %.2f%%'
. The space should be before %.2f
since that’s where your percentage value is being formatted.
Example here:
# some dummy values size = 1 contentsize = 5 fmt = 'Download : %s%s %.2f%%' % ('█' * int(size * 20 / contentsize), '' * (20 - int(size * 20 / contentsize)), float(size / contentsize * 100)) print(fmt)
Output:
Download : ████ 20.00%
Edit: also, I realized your second %s
is unnecessary because you’re trying to insert '' * (20 - int(size * 20 / contentsize))
, but ''
is zero-length, so it doesn’t actually add anything. This would do the equivalent of what you’re trying to achieve (notice one fewer %s
, and removing the second calculation you have).
# some dummy values size = 1 contentsize = 5 fmt = 'Download : %s %.2f%%' % ('█' * int(size * 20 / contentsize), float(size / contentsize * 100)) print(fmt)