我已经在自定义桌面上工作了一段时间(感谢所有帮助过的人)并且我:我正在尝试为用户编写一个“控制”桌面,主要是,顾名思义,可以很好地控制他们的电脑。这与pygame有什么关系?控制桌面的功能之一是播放音乐。除了播放的声音,我什么都没有。它总是决定制作“流行音乐”而不是播放实际歌曲。任何帮助将不胜感激,因为我有点急于在夏天结束之前推出“测试版”。
代码:
class control():
def ctr(self):
print("Going to control Desktop for Jupee...")
midnightbg = pygame.image.load("MidNightUI.jpg").convert_alpha()
midnightbg = pygame.transform.scale(midnightbg, (winx, winy))
screen.blit(midnightbg, (0, 0))
pygame.display.update()
songlist = []
songlist = os.listdir("/Users/"+getpass.getuser()+"/Desktop/JupeeMusic")
pygame.time.wait(500)
a = 0
songsinlist = 0
for things in songlist:
songsinlist = songsinlist + 1
songlist.remove(".DS_Store")
songsinlist = songsinlist - 1
pygame.mixer.init()
for items in songlist:
print("Song found : "+items)
while 1:
mx, my = pygame.mouse.get_pos()
if a > songsinlist-1:
a = 0
for event in pygame.event.get():
if event.type == MOUSEBUTTONDOWN:
print(mx, my, "is the location that the mouse button was pressed.")
elif event.type == QUIT:
pygame.quit()
raise SystemExit
elif event.type == KEYDOWN:
if event.key == K_LMETA:
print("Going to main desktop again...")
setup().setdesk()
elif event.key == K_RMETA:
print("Going to main desktop again...")
setup().setdesk()
elif event.key == ord("p"):
song = pygame.mixer.Sound(songlist[a])
song.play(0)
pygame.time.wait(600)
a = a + 1
elif event.type == MOUSEBUTTONDOWN:
if mx <= 50 and my <= 50:
song = pygame.mixer.Sound(songlist[a])
song.play(0)
pygame.time.wait(600)
a = a + 1
这是在 Mac 上。