更改Tkinter滚动条小部件Python的外观 [英] Change the look of the Tkinter scrollbar widget Python
问题描述
我想知道是否可以更改Tkinter滚动条的外观?我已经在网上搜索过,但是找不到我想要的东西.我想将其从外观更改为更多的滚动条,就像您在Google Chrome中看到的那样.有任何想法吗?我只需要向正确的方向推动即可.
I was wondering if there was a way to change the look of the Tkinter scroll bar? I have searched online but I could not find anything on what I was looking for. I would like to change it from the look it has to more of a scroll bar that you would see in Google Chrome. Any ideas? I just need a push in the right direction.
推荐答案
ttk样式是必经之路. http://www.tkdocs.com/tutorial/styles.html
ttk styles are the way to go. http://www.tkdocs.com/tutorial/styles.html
我将plastik主题用作很好的参考,它是基于图像的主题.
I use the plastik theme as a good reference, it is an image based theme.
然后您可以用自己的图像替换图像.
You can then replace the images with your own.
获取源文件和文件: http://svn.python.org/projects/sandbox/trunk/ttk-gsoc/samples/plastik_theme.py
to get the source and files: http://svn.python.org/projects/sandbox/trunk/ttk-gsoc/samples/plastik_theme.py
我刚刚运行了2to3转换工具,并且在python3中效果很好
I just ran the 2to3 conversion tool and works great in python3
假设您将所有图像移动到一个名为/img的相对路径,就可以做到
Assuming you move all the images to a relative path called /img you can do
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小部件
Note: You have to use the ttk.Scrollbar widget not the tkinter widget
这篇关于更改Tkinter滚动条小部件Python的外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!