【问题标题】:Change the look of the Tkinter scrollbar widget Python更改 Tkinter 滚动条小部件 Python 的外观
【发布时间】:2015-01-10 01:22:39
【问题描述】:

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

【问题讨论】:

    标签: python tkinter styles scrollbar


    【解决方案1】:

    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 小部件

    【讨论】:

    • 为什么要在代码的最后一行重新创建滚动条,而不是打包它?另外,您的最后一行代码是scrollbar = Scrollbar(root)。自从您将 ttk 导入为 ttk 后,您不会在 Scrollbar 前面缺少 ttk. 吗?
    猜你喜欢
    • 2011-10-21
    • 2015-04-07
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    相关资源
    最近更新 更多