有没有办法在 Tkinter 中使用功能区工具栏? [英] Is there a way to use ribbon toolbars in Tkinter?

查看:22
本文介绍了有没有办法在 Tkinter 中使用功能区工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有决定在我的下一个项目中使用什么语言和工具.我很想使用 python,但我想实现功能区工具栏.在 Tk 中做了一些工作(http://www.ellogon.org/petasis/bibliography/Tcl2010/TkRibbon.pdf),但看起来它尚未在 tkinter 中实现.有什么我可以做的事情吗?

I am yet to decide what language and tools to use for my next project. I would love to use python, but I would like to implement ribbon toolbars. Some work has been done in Tk (http://www.ellogon.org/petasis/bibliography/Tcl2010/TkRibbon.pdf), but it looks like it hasn't been implemented in tkinter yet. Is there anything I can do to get this to work?

推荐答案

您需要为此创建一个包装器并获得您可以使用的二进制文件版本.我构建了它用于 Python 3.4 并将其复制到 tkribbon1.0-x86_64.zip.您应该将其解压到 Python/tcl 子目录中,以便 python 使用的 tcl 版本可以加载它.

You need to create a wrapper for this and get a version of the binary you can use. I built this for use with Python 3.4 and copied it to tkribbon1.0-x86_64.zip. You should unzip this in the Python/tcl subdirectory so the version of tcl used by python can load it.

一个最小的包装器看起来像这样:

A minimal wrapper looks like this:

from tkinter import Widget
from os import path

class Ribbon(Widget):
    def __init__(self, master, kw=None):
        self.version = master.tk.call('package','require','tkribbon')
        self.library = master.tk.eval('set ::tkribbon::library')
        Widget.__init__(self, master, 'tkribbon::ribbon', kw=kw)

    def load_resource(self, resource_file, resource_name='APPLICATION_RIBBON'):
        """Load the ribbon definition from resources.

        Ribbon markup is compiled using the uicc compiler and the resource included
        in a dll. Load from the provided file."""
        self.tk.call(self._w, 'load_resources', resource_file)
        self.tk.call(self._w, 'load_ui', resource_file, resource_name)

if __name__ == '__main__':
    import sys
    from tkinter import *
    def main():
        root = Tk()
        r = Ribbon(root)
        name = 'APPLICATION_RIBBON'
        if len(sys.argv) > 1:
            resource = sys.argv[1]
            if len(sys.argv) > 2:
                name = sys.argv[2]
        else:
            resource = path.join(r.library, 'libtkribbon1.0.dll')
        r.load_resource(resource, name)
        t = Text(root)
        r.grid(sticky=(N,E,S,W))
        t.grid(sticky=(N,E,S,W))
        root.grid_columnconfigure(0, weight=1)
        root.grid_rowconfigure(1, weight=1)
        root.mainloop()
    main()

运行它会使用 tkribbon dll 内置的资源,看起来像 .复杂的部分是将一些 Ribbon 标记资源放入 DLL 中以供加载.

Running this uses the resources built-in to the tkribbon dll and looks like . The complicated bit is going to be getting some Ribbon markup resources into a DLL for loading.

您可以使用此示例从现有应用程序加载色带.例如,python Ribbon.py c:\Windows\System32\mspaint.exe MSPAINT_RIBBON 将从 mspaint 加载功能区资源.在这种情况下,必须包含资源名称,因为默认值为 APPLICATION_RIBBON.对于您自己的功能区,使用 uicc 构建 .rc 文件,然后 rc/r file.rc 生成 .res 文件,最后 link -dll -out:file.dll 文件.rc -noentry -machine:AMD64 似乎可以生成与此扩展一起使用的仅资源 DLL.

You can use this example to load ribbons from existing applications. For instance, python Ribbon.py c:\Windows\System32\mspaint.exe MSPAINT_RIBBON will load up the ribbon resource from mspaint. The resource name in this case has to be included as the default is APPLICATION_RIBBON. For your own ribbon, using uicc to build a .rc file, then rc /r file.rc to produce a .res file and finally link -dll -out:file.dll file.rc -noentry -machine:AMD64 seems to work to produce a resource only DLL that works with this extension.

这篇关于有没有办法在 Tkinter 中使用功能区工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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