"""给Python代码每一行加上按键精灵的SayString以便启动按键精灵时能自动发送Python代码到记事本,这是我录制抖音时的一个辅助脚本.""" from tkinter.filedialog import * import os filename = askopenfilename(filetypes=[("py源文件", "*.py"),("txt文件", "*.txt"),("所有文件", "*.*")]) fld = os.path.split(filename)[0] + os.sep fn = os.path.split(filename)[-1] basename = os.path.splitext(fn)[0] #带扩展名的文件名称 f = open(filename,encoding = 'utf-8') string = "" for line in f: s = line.rstrip() string = string + "SayString " + chr(34) + s + chr(34) + "\n" string = string + "SayString vblf \n" string = string + "Delay 50 \n" #string = string + "SayString vbcrlf\n" f.close() print(string) f = open(fld + basename + "_SayString.txt",mode='w',encoding='utf-8') f.write(string) f.close()
目前为止有一条评论