如何更改 Tkinter ScrolledText 小部件的滚动条颜色?
我在 Tkinter GUI 中使用模块 ScrolledText
。
我希望更改 ScrolledText
小部件中包含的 Scrollbar
的颜色,但我遇到了一些困难。
我的语法是正确的(根据文档)。
Box = ScrolledText(root)
Box.vbar.config(troughcolor = 'red', bg = 'blue')
Box.pack()
然而,滚动条仍然具有标准的灰色。
我知道语法是正确的,因为执行其他操作,例如:
Box.vbar.config(cursor = 'target')
... 完全按照其应有的方式工作。
但是,尝试更改浮雕
、边框宽度
或颜色似乎没有任何效果。
为什么会发生这种情况?
规格:
Python 2.7.1
Tkinter
Windows 7
闲置的
I'm using the module ScrolledText
in a Tkinter GUI.
I wish to change the colour of the Scrollbar
encompassed in the ScrolledText
widget, but I'm having some difficulty.
My syntax is correct (according to documentation).
Box = ScrolledText(root)
Box.vbar.config(troughcolor = 'red', bg = 'blue')
Box.pack()
However, the scrollbar still has the standard grey colour.
I know the syntax is correct, because doing other things such as:
Box.vbar.config(cursor = 'target')
...works exactly as it should.
However, attempting to change the relief
, borderwidth
or colors don't seem to have any effect.
Why is this happening?
Specs:
Python 2.7.1
Tkinter
Windows 7
IDLE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Tk 滚动条小部件 (vbar) 是 Windows 中的本机滚动条。它的外观取决于 Windows 主题。如果重要的话,考虑切换工具包;我知道 PyQt4 可以让你在 Windows 上设置滚动条的样式。
The Tk Scrollbar widget (vbar) is a native scrollbar in Windows. Its appearance depends on the Windows theme. Consider switching toolkits if it matters; I know PyQt4 will let you style the scrollbar on Windows.
据我所知,在 Windows 上格式化滚动条确实很困难。下面是我编写的滚动条程序的一些代码。我正在尝试开发一些应该具有这些选项的软件,但在我看来,这就像一个小部件的大量代码,其主要用途 Tkinter 做得更好。然而,该程序应该允许您将图像插入箭头、槽和滑块以及更改它们的颜色。
From what I've read it's really difficult to format scrollbars on Windows. Below is some code for a scrollbar programme which I've written. I'm trying to develop some software which should have these kinds of options, but this seems to me like a lot of code for a widget whose main purpose Tkinter does better. However, the programme should allow you to insert images into the arrows, trough and slider as well as change their colour.
不要使用 Box.vbar.config(troughcolor = 'red', bg = 'blue') 更改配置来配置
Box.vbar.configure(troughcolor = 'red', bg = '蓝色')
Instead of using
Box.vbar.config(troughcolor = 'red', bg = 'blue')
change config to configureBox.vbar.configure(troughcolor = 'red', bg = 'blue')