def CreateText(win, text, x, y, size, font, color, style):
txtObject = Text(Point(x,y), text)
if size==None:
txtObject.setSize(12)
else:
txtObject.setSize(size)
if font==None:
txtObject.setFace("courier")
else:
txtObject.setFace(font)
if color==None:
txtObject.setTextColor("black")
else:
txtObject.setTextColor(color)
if style==None:
txtObject.setStyle("normal")
else:
txtObject.setStyle(style)
return txtObject
def FlashingIntro(win, numTimes):
txtIntro = CreateText(win, "CELSIUS CONVERTER!", 5,5,28)
for i in range(numTimes):
txtIntro.draw(win)
sleep(.5)
txtIntro.undraw()
sleep(.5)
I'm trying to get the CreateText
function to create a text object with my "default" values if the parameters are not used. (I've tried it with blank strings ""
instead of None
and no luck) I'm fairly new to Python and have little programming knowledge.
You need to specify default values for the arguments:
ReplyDeletedef CreateText(win, text, x, y, size=None, font=None, color=None, style=None): or, putting your real defaults in so you don't need if statments:
def CreateText(win, text, x, y, size=12, font="courier", color="black", style="normal"): txtObject = Text(Point(x,y), text) txtObject.setSize(size) txtObject.setFace(font) txtObject.setTextColor(color) txtObject.setStyle(style)
return txtObject