6

I am using the ttk.Progressbar in my app. I have scoured the net for an answer but no avail.

I have the following code which is working well. But I want to change the thickness of the bar.

progressbar = ttk.Progressbar(myGui, orient=HORIZONTAL,
                              length=400, mode="determinate",
                              variable=value_progress,
                              )
progressbar.pack()

I want the length to still be 400, but from the top of the bar to the bottom, I wish to decrease that so its half or less then half. (I want my bar on a diet, so to say)

But I am beating my head against the wall to figure out a solution.

Andy ideas? Thanks in advance.

4

3 回答 3

7

如果您必须使用 xpnative 主题或类似的主题,那么您可能无法选择以传统方式更改厚度。但是,如果您使用默认主题,则可以使用样式配置粗细。可能还有其他主题也可以让您执行此操作,如果您要经常使用程序的外观和感觉,您可能希望使用这些主题。

from Tkinter import *
from ttk import *

def main():
    root = Tk()
    s = Style()
    s.theme_use("default")
    s.configure("TProgressbar", thickness=50)
    pb = Progressbar(root, style="TProgressbar")
    pb.pack() 
    root.mainloop()

main()
于 2013-08-09T04:52:08.740 回答
6

ttk进度条似乎缺少 Python 中的宽度选项。

使用解决方法(此处)解决 Tkinter 按钮的问题。由此我已经能够创建一个可行的解决方案。

解决问题的关键是将进度条添加到画布内的窗口中。在画布内使用窗口不会导致在添加小部件时画布调整大小,这意味着我们可以控制进度条的宽度。

我创建了一些工作示例代码:

from ttk import Progressbar
import Tkinter

class Example(Tkinter.Frame):
    def __init__(self, parent):
        Tkinter.Frame.__init__(self, parent)
        self.parent = parent
        self.initUI()

    def initUI(self):
        value_progress =50
        self.parent.title("Progressbar Thingymawhatsit")
        self.config(bg = '#F0F0F0')
        self.pack(fill = Tkinter.BOTH, expand = 1)
                #create canvas
        canvas = Tkinter.Canvas(self, relief = Tkinter.FLAT, background = "#D2D2D2",
                                            width = 400, height = 5)

        progressbar = Progressbar(canvas, orient=Tkinter.HORIZONTAL,
                                  length=400, mode="indeterminate",
                                  variable=value_progress,

                                  )
        # The first 2 create window argvs control where the progress bar is placed
        canvas.create_window(1, 1, anchor=Tkinter.NW, window=progressbar)
        canvas.grid()


def main():
    root = Tkinter.Tk()
    root.geometry('500x50+10+50')
    app = Example(root)
    app.mainloop()

if __name__ == '__main__':
    main()

所以总结一下进度条是一样大的,但是你看不到一半!

于 2013-07-28T22:58:59.223 回答
6

您可以只使用ipady包管理器的选项。

progressbar = ttk.Progressbar(myGui, orient=HORIZONTAL,
                          length=400, mode="determinate",
                          variable=value_progress,
                          )
progressbar.pack(ipady=10)
于 2018-12-17T22:57:48.170 回答