Python 无法保存海龟图形图像
我正在使用excel VBA调用python文件来绘制海龟图形并将其保存在.ps文件中,但没有保存该文件。当我直接从命令提示符执行时,它会保存文件。 有人能帮忙吗 以下是VBA命令Python 无法保存海龟图形图像,python,excel,vba,turtle-graphics,Python,Excel,Vba,Turtle Graphics,我正在使用excel VBA调用python文件来绘制海龟图形并将其保存在.ps文件中,但没有保存该文件。当我直接从命令提示符执行时,它会保存文件。 有人能帮忙吗 以下是VBA命令 Sub RunPythonScript() 'Declare our variablesstrong text Dim objShell As Object Dim PythonExe, PythonScript As String Dim a, b, c, k, t As Integer 'Creae as a n
Sub RunPythonScript()
'Declare our variablesstrong text
Dim objShell As Object
Dim PythonExe, PythonScript As String
Dim a, b, c, k, t As Integer
'Creae as a new shell Object
Set objShell = VBA.CreateObject("Wscript.Shell")
a = Range("e3").Value
b = Range("f3").Value
c = Range("g3").Value
k = Range("h3").Value
'Provide the file path to the Python Exe
PythonExe = """C:\Windows\py.exe"""
PythonScript = "D:\comsol\code0.5.py"
objShell.Run PythonExe & PythonScript & " " & a & " " & b & " " & c & " " & k
End Sub
下面是python代码
import os
import sys
t=turtle.Turtle()
a=int(sys.argv[1])
b=int(sys.argv[2])
c=int(sys.argv[3])
k=int(sys.argv[4])
for i in range(k):
t.color("Black","Black")
t.begin_fill()
t.forward(a)
t.left(90)
t.forward(b)
t.left(90)
t.forward(a)
t.left(90)
t.forward(b)
t.end_fill()
t.penup()
t.left(90)
t.forward(c+a)
t.pendown()
t.color("Yellow","Yellow")
t.begin_fill()
t.forward(a)
t.left(90)
t.forward(b)
t.left(90)
t.forward(a)
t.left(90)
t.forward(b)
t.end_fill()
t.penup()
t.left(90)
t.forward(c+a)
t.pendown()
command=turtle.getscreen().getcanvas().postscript(file='canva1.ps')
os.system(command)
turtle.done()
当您将
PythonExe&PythonScript
更改为PythonExe&PythonScript
时会发生什么情况?是的,我尝试过,它不起作用检查a、b、c和k的值是否正常?尝试从PythonExe&PythonScript&&&a&&b&&c&&k
获取字符串,然后查看得到的结果。也可以使用它从命令行运行它。它工作吗?是的,它在命令行上打印正确的数据。唯一的问题是,当从VBAbeforeobjShell执行时,它没有保存postscript文件。运行PythonExe&PythonScript&&a&&b&&c&&k
,您能否键入Debug.Print PythonExe&&PythonScript&&a&&b&&c&&k
,并共享您得到的内容?