简体   繁体   中英

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.


在此处输入图片说明

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()

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM