Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有办法在Tkinter中使用功能区工具栏?_Python_Tkinter - Fatal编程技术网

Python 有没有办法在Tkinter中使用功能区工具栏?

Python 有没有办法在Tkinter中使用功能区工具栏?,python,tkinter,Python,Tkinter,我还没有决定下一个项目使用什么语言和工具。我很想使用python,但我想实现功能区工具栏。在Tk()中已经完成了一些工作,但是看起来它还没有在tkinter中实现。我能做些什么来让它工作吗?您需要为此创建一个包装器,并获得一个可以使用的二进制版本。我为使用Python3.4构建了它,并将其复制到。您应该在Python/tcl子目录中解压它,以便Python使用的tcl版本可以加载它 最小包装器如下所示: from tkinter import Widget from os import path

我还没有决定下一个项目使用什么语言和工具。我很想使用python,但我想实现功能区工具栏。在Tk()中已经完成了一些工作,但是看起来它还没有在tkinter中实现。我能做些什么来让它工作吗?

您需要为此创建一个包装器,并获得一个可以使用的二进制版本。我为使用Python3.4构建了它,并将其复制到。您应该在Python/tcl子目录中解压它,以便Python使用的tcl版本可以加载它

最小包装器如下所示:

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中内置的资源,如下所示。复杂的一点是将一些功能区标记资源放入DLL中进行加载


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

我想你需要围绕
tkribbon
编写自己的包装库,因为显然还没有人这样做过。或者写一些代码来模拟那种工具栏……我已经试过了,它确实工作得很合理,所以过了一段时间,我会接受它。不过,也许有一天会有人写一个包装器。