如何使用python打开xaml文件

2024-04-25 11:37:15 发布

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

我正在尝试使用提供的python脚本打开和保存xaml文件, 但是is给了我一个错误如下

import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")

from System.Windows import Window, Application
from System.Windows.Markup import XamlReader
from System.IO import File, Path

class XamlWindow(Window):
    def __init__(self, name):
        self.load_xaml(name)

    def load_xaml(self, name):
        xaml_file = File.OpenRead(Path.GetFullPath(name))
        self.Content = XamlReader.Load(xaml_file)

Application().Run(XamlWindow("Mail.xaml"))

我没有打开文件,而是出现了以下错误。你知道吗

Traceback (most recent call last):
  File "D:\Desktop\UiPathTutorials\Read\Outlook\OutlookMail\OpeningAtext.py", line 2, in <module>
    clr.AddReference("PresentationFramework")
System.IO.FileNotFoundException: Unable to find assembly 'PresentationFramework'.
   at Python.Runtime.CLRModule.AddReference(String name)

Tags: 文件namefromimportselfapplicationwindows错误