无法保存乌龟图形图像

时间:2020-02-27 10:51:58

标签: 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 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()

0 个答案:

没有答案