Python带子应用程序使用Tkin

2024-10-02 20:36:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用pythontkinter制作一个功能区样式的应用程序。在

patthoyts回答的以下线程中的包装器似乎工作得很好:

但是我正在努力为我自己的丝带设计创建.dll。我使用了Visual Studio 2017的RibbonWinForms加载项导出功能区草稿项目的dll。RibbonWinForms似乎工作得很好。在

将从patthoyts(第一个链接)下载的dll替换为导出的dll(并相应地重命名文件)不起作用并产生错误(_tkinter.tc错误:找不到符号“Tkribbon_Init”)。 我保存了visualstudiohere中的各种文件(包括导出的带有原始名称的.dll)。在

为什么下面的代码使用patthoyts dll而不是我的?(有关.dll的信息,请参阅上面的链接

我将非常感谢,如果有人可以建议什么代码更改或dll导出更改需要使这个工作?在

或者,如果我过于复杂化了,有一种更简单的方法来实现用python编写的功能区应用程序,那就太好了?在

以下是patthoyts代码供参考,他的dll也保存在上面的amazon链接上:

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()

Tags: thenamefromimportselfmastersysload