tkinter.ttk.Progressbar:如何更改单杠的粗细 [英] tkinter.ttk.Progressbar: How to change thickness of a horizontal bar

查看:47
本文介绍了tkinter.ttk.Progressbar:如何更改单杠的粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用 ttk.Progressbar.我已经在网上搜索了答案,但无济于事.

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

我希望长度仍然是 400,但是从条形图的顶部到底部,我希望将其减少到一半或不到一半.(可以这么说,我想要我的酒吧节食)

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.

推荐答案

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

The ttk progress bar appears to lack the width option in Python.

使用变通方法(此处)解决 Tkinter 按钮的问题.由此,我已经能够创建一个有效的解决方案.

Using a work around (here) for an issue with a Tkinter Button. From this I have been able to create a working solution.

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

The key to solving the issue was to add the progress bar to a window inside the canvas. Using a window inside the canvas doesn't cause the canvas to resize when the widget is added which means we can control the width of the progress bar.

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

I have created some working example code:

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

所以总而言之,进度条大小相同,但您看不到它的一半!

So to sum up the progress bar is the same size but you just cant see half of it!

这篇关于tkinter.ttk.Progressbar:如何更改单杠的粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆