如何使用Python打开Photoshop并在已经创建的PSD文件模板中添加userinput数据?

2024-05-16 08:41:23 发布

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

当我尝试使用Python打开Photoshop时,我遇到了一个错误。我制作了一个应用程序,使用Tkinter获取用户数据,然后将数据附加到CSV文件中。我还希望它使用我在Photoshop上创建的模板生成一幅包含这些数据的图像。但由于某些原因,我的程序正确打开Photoshop,但也会生成错误消息:

Traceback (most recent call last):
 File "d:\Coding\Python Scripts\Dr Nikhil Prescription App\PS_test.py", line 3, in <module>
   psApp.Open("Presc_Template.psd")
 File "<COMObject Photoshop.Application>", line 2, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'Illegal argument - argument 
1\n- Expected a reference to an existing File/Folder', None, 0, -2147220262), None)

这对我来说是不好的,因为我将把它变成一个软件。 这是代码

main.py

import win32com.client, os
psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open("D:\Coding\Python Scripts\Dr Nikhil Prescription App\Prescription Generator\Presc_Template.psd")
doc = psApp.Application.ActiveDocument
layer_facts = doc.ArtLayers["Layer"] #Opening the specific layer
text_of_layer = layer_facts.TextItem
text_of_layer.contents = "This is a test." #Making changes to the text in the layer

我应该做些什么来克服这个问题,以便我能够克服每次尝试使用Python打开Photoshop时不断出现的错误?我的目的是自动将CSV文件中的数据添加到Photoshop模板中,然后在用户每次需要时进行渲染


Tags: 文件csvthe数据text用户inlayer