Search code examples
pythonpython-2.7tkinterttk

intersect a progress bar in Tkinter


Like the title says, I want to intersect a progress bar in Tkinter at some variable position. See the image for what I want to achieve, those red vertical lines that I edited into the image.


enter image description here

The idea is to put text like "||" inside the bar and color it differently so it should look like what I want to achieve. I have seen a couple of examples with text being put into the progress bar, but it was always right in the middle of the bar which doesn't work for me.


Here is the code that generates progress bars.

import ttk
from Tkinter import *
import random
master = Tk()

stl = ttk.Style()
stl.theme_use("winnative")
stl.configure("colour.Horizontal.TProgressbar", background="lime green")

for i in range(0,4):
    prgb = ttk.Progressbar(master, orient = "horizontal", length = 150, mode = "determinate", style = "colour.Horizontal.TProgressbar")
    prgb.grid(row=i, column=0, pady=10) 
    prgb["maximum"] = 1.0
    x = random.random()
    prgb["value"] = x


master.mainloop()

Solution

  • The ProgressBar widget doesn't support this. However you could create a small colored Frame and use place to put it on top of the progress bar.

    Example:

    for i in range(0,4):
        prgb = ttk.Progressbar(...)
        ...
        x = random.random()
        ...
        marker = Frame(prgb, width=4, background="red")
        position = random.uniform(0,x)
        marker.place(relx=position, rely=.5, anchor="w", relheight=.5)
    

    I don't have access to a windows machine, but this is what it looks like on my mac:

    enter image description here