Python将屏幕截图代码转换为函数
问题描述:
我已经为我的代码创建了截图方法,但是我想将所述代码转换为函数,因为我想多次使用它。这是代码:Python将屏幕截图代码转换为函数
import os
for i in range(20):
print("")
print("Screenshot taken.")
for i in range(20):
print("")
os.system("screencapture Screenshottie.png")
os.system('Screenshottie.png')
格式编辑
答
我无法理解你的完全问题,但在Python中,当你想做一个函数时,你应该这样使用def:
import os
def screenshotter():
os.system("screencapture Screenshottie.png")
os.system('Screenshottie.png')
return "Screenshot taken."
for i in range(20):
print(screenshotter())
print("Done.")
答
我建议找了一个基本的Python介绍/教程,但在任何情况下:
def screenshot(fname):
print("Screenshot taken.")
os.system("screencapture {}".format(fname))
os.system(fname)
你想要的函数内的代码是什么? –
我想基本上把我上面发布的所有东西放到它里面,这样我就可以输入一行,并在需要时激活该代码,而不必输入所有这些行。 – INeedHelpAndFast
方法和功能是一回事。你还应该阅读_very_,_very_基本的Python,因为其中大部分解释了函数如何工作 – OptimusCrime