python - 我想在我的电脑启动时运行我的程序

标签 python notifications

此代码可以读取字符串并使用 vocal 提取输出。代码运行没有问题。我面临的唯一问题是每次打开电脑时我都想运行 .py 文件。我也将 .py 文件放在启动文件夹中,但没有任何反应。这是我的代码:

from plyer import notification
import getpass
import os
import speech_recognition as sr
import playsound
from gtts import gTTS

USER_NAME = getpass.getuser()
notification.notify(
# title of the notification,
# the body of the notification
message="Welcome",
# the notification stays for 50sec
timeout=0.5,
           )

def speak(text):
   tts = gTTS(text=text, lang="en")
   filename = "voice.mp3"
   tts.save(filename)
   playsound.playsound(filename)

speak("Welcome Michael")

最佳答案

一个解决方案是一个调用 python 代码的批处理文件。如果没有实际调用该文件,则启动文件中的文件将不会执行任何操作。在 .BAT 文件中,您需要两件事:

  1. 你的 python 解释器的路径
  2. 脚本的路径

然后通过将批处理文件放在启动文件夹中来调用它

"interpreter.exe""your_script.py"

关于python - 我想在我的电脑启动时运行我的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66987927/

相关文章:

python - 将度数转化为三电机运动

Android 无障碍服务检测通知

python - 更新 Django 中用户对象的变量值

c# - Windows 10通用应用程序。如何触发后台任务?

android - 我的代码有什么问题 - 通知 - 没有声音没有振动

android - 我怎样才能清除这个通知

iphone - 重置 iOS 应用程序的推送通知设置?

python - 如何运行存储在不同文件中的 python 函数

python - 设置值后pyQt进度对话框栏保持为空

python - 我如何让python将瑞典语字母(åäö)写入html文件?