Skip to main content
 首页 » 编程设计

python之更改 Tkinter 滚动条小部件 Python 的外观

2024年10月25日11tintown

我想知道是否有办法改变 Tkinter 滚动条的外观?我在网上搜索过,但找不到任何我要找的东西。我想将其从外观更改为您在 Google Chrome 中看到的更多滚动条。有任何想法吗?我只需要朝着正确的方向插入。

请您参考如下方法:

ttk 样式是必经之路。 http://www.tkdocs.com/tutorial/styles.html

我使用 plastik 主题作为一个很好的引用,它是一个基于图像的主题。

然后您可以用自己的图像替换这些图像。

获取源和文件: http://svn.python.org/projects/sandbox/trunk/ttk-gsoc/samples/plastik_theme.py

我刚刚运行了 2to3 转换工具并且在 python3 中运行良好

假设您将所有图像移动到名为/img 的相对路径,您可以这样做

import tkinter.ttk as ttk 
import os 
import plastik 
plastik.install((os.getcwd()+'/img/plastik')) 
 
scrollbar = ttk.Scrollbar(root) 
scrollbar.pack(side=RIGHT, fill=Y) 
 
listbox = Listbox(root) 
listbox.pack() 
 
for i in range(100): 
    listbox.insert(END, i) 
 
listbox.config(yscrollcommand=scrollbar.set) 
scrollbar.config(command=listbox.yview) 

注意:您必须使用 ttk.Scrollbar 小部件而不是 tkinter 小部件