如何制作功能
def InputName():
Name = input("Name: ")
def InputCourseName():
CourseName = input("Course: ")
为我设置名称和课程名称:
def Criacao(Name, CourseName):
global Fonte, Output, CorTexto, Raw
base = Image.open(Raw)
draw = ImageDraw.Draw(base)
draw.text((5,5), Name.upper(), font=Fonte, fill=CorTexto)
draw.text((6,5), CourseName.upper(), font=Fonte, fill=CorTexto)
如果我跑:Criacao(InputName(), InputCourseName())
?
答案 0 :(得分:5)
您应该开始使用return
def InputName():
name = input("Name: ")
return name
def InputCourseName():
courseName = input("Course: ")
return courseName
然后,您可以使用返回的值分配给局部变量
def Criacao():
name = InputName() # We are using the returned values here
courseName = InputCourseName()
global Fonte, Output, CorTexto, Raw
base = Image.open(Raw)
draw = ImageDraw.Draw(base)
draw.text((5,5), name.upper(), font=Fonte, fill=CorTexto)
draw.text((6,5), courseName.upper(), font=Fonte, fill=CorTexto)
答案 1 :(得分:2)
是的,如果,>>您从Name
函数返回InputName()
并从CourseName
函数返回InputCourseName()
,就可以。