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()
您需要为此创建一个包装器,并获得可以使用的二进制文件的版本。我构建了这个用于python3.4并将其复制到tkribbon1.0-x86_64.zip。您应该在Python/tcl子目录中解压缩它,以便Python使用的tcl版本可以加载它。在
最小包装如下所示:
运行它使用tkribbon dll中内置的资源,看起来像。复杂的一点是将一些功能区标记资源放入DLL以进行加载。在
您可以使用此示例从现有应用程序加载功能区。例如,
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 file.rc -noentry -machine:AMD64
似乎可以生成一个仅用于此扩展名的资源DLL。在相关问题 更多 >
编程相关推荐