Python 代码在pycharm中完全工作,但在raspberry中部分工作
当我要求pycharm运行程序时,程序的所有功能都正常工作。 然而,当我要求我的raspberry Pi运行它时,它跳过了Python 代码在pycharm中完全工作,但在raspberry中部分工作,python,raspberry-pi,pygame,Python,Raspberry Pi,Pygame,当我要求pycharm运行程序时,程序的所有功能都正常工作。 然而,当我要求我的raspberry Pi运行它时,它跳过了结束计时器。所以这首歌一直在播放。在窗户上,歌声会停止。是什么造成了这种小小的差异 import datetime import pygame def Clockupdate(time): Timer = "21:56:00" EndTimer = '21:56:20' if time == Timer: playsound()
结束计时器。所以这首歌一直在播放。在窗户上,歌声会停止。是什么造成了这种小小的差异
import datetime
import pygame
def Clockupdate(time):
Timer = "21:56:00"
EndTimer = '21:56:20'
if time == Timer:
playsound()
if time == EndTimer:
global a
a = False
def secondrefresher():
newtime = ""
oldtime = datetime.datetime.now()
a = str(oldtime.hour)
b = str(oldtime.minute)
c = str(oldtime.second)
if int(c) < 10:
c = "0"+str(c)
if int(b) < 10:
b = "0"+str(b)
curtime = (a+":"+b+':'+c)
if curtime != newtime:
newtime = curtime
Clockupdate(newtime)
def playsound():
pygame.mixer.init()
pygame.mixer.music.load("ABTPP.mp3")
pygame.mixer.music.play()
global a
a = True
while a:
secondrefresher()
导入日期时间
导入pygame
def时钟更新(时间):
计时器=“21:56:00”
结束计时器='21:56:20'
如果时间==计时器:
播放声音()
如果时间==结束计时器:
全球a
a=错误
def secondrefresher():
newtime=“”
oldtime=datetime.datetime.now()
a=str(oldtime.hour)
b=str(旧时间分钟)
c=str(oldtime.second)
如果int(c)<10:
c=“0”+str(c)
如果int(b)<10:
b=“0”+str(b)
curtime=(a+“:”+b+“:”+c)
如果柯蒂姆新时代:
newtime=curtime
时钟更新(新时间)
def playsound():
pygame.mixer.init()
pygame.mixer.music.load(“ABTPP.mp3”)
pygame.mixer.music.play()
全球a
a=正确
而a:
第二复习者()
可能与您的问题无关,但这段代码有点伤了我的眼睛。请考虑使用<代码>日期时间> /代码>对象来表示和比较时间。学习它们的格式也将为您节省大量时间(双关缩进),使程序足够小,适合这里我刚刚复制并删除了一些我的主代码。datetime
对象在那里使用得更仔细;)。但它可能已经花了大量的时间来复制和编写一个新的时间函数,所以也许我今晚会更新它。