繁体   English   中英

如何从python中的不同文件调用函数?

[英]How to call a function from a different file in python?

这些文件位于同一目录中。 这是我试图导入不同文件的函数:

RedInfantry = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\InfantryRedV20.gif"
screen.addshape(RedInfantry)

#Red Infantry
def InfantryRed(x, y):
    turtle = Turtle()
    turtle.shape(RedInfantry)
    turtle.penup()
    turtle.goto(x, y)
    Health = 10
    Armour = 0
    Attack = 1
    Movement = 2
    Capture = True

    return turtle

这就是我试图做的:

from ImagesV4 import *
import turtle

ImagesV4.InfantryRed(200,200)
screen.update()

当我运行代码时,图像不会出现在屏幕上并且没有错误,只是一个空屏幕。

import ImagesV4 as im 


im.InfantryRed(200,200)
im.screen.update()
im.screen.exitonclick()  #using this for screen to hold

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM