Skip to main content
 首页 » 编程设计

python之如何使用pygame模块

2024年08月12日34hnrainll

import pygame 
import time 
import datetime 
cup=int(input("please enter how many cups you want to drink in a day: ")) 
interval=int(input("please enter after how many minutes we should remind you: ")) 
waterat=time.time() #gives some random time which will help we know the duration 
intervalsec=interval*60 
if (cup>0): 
    if (time.time()-waterat)>intervalsec: 
        print("DRINK WATER!!!!!!") 
        while (true): 
            pygame.mixer.music.load('water.mp3') 
            pygame.mixer.music.play(-1) 
            #plays infinite time 
            word=input("enter done if you done drinking water: ") 
            if (word.lower=="done"): 
                cup=cup-1 
                waterat=time.time() 
                f=open("drinktime.txt","a") 
                f.write(datetime.datetime.now()) 
                #datetime function is inside datetime module 
                break 
time.sleep(60) 
#program sleep for 60 sec 

我得到的错误是-

Traceback (most recent call last): 
  File "C:/Users/Nishant/Desktop/practice/water reminder/drink.py", line 1, in <module> 
    import pygame 
  File "C:\Users\Nishant\AppData\Roaming\Python\Python37\site-packages\pygame\__init__.py", line 120, in <module> 
    from pygame.base import * 
ModuleNotFoundError: No module named 'pygame.base' 

请您参考如下方法:

你的问题不是很好。你应该给我们更多的细节,这样我们才能更好地回答你。你是否正确安装了pygame?你有什么版本的 Python?

我复制了你的代码,它的解释很好。这意味着您根本没有正确导入 pygame。

我想你会在这个帖子中找到答案:

Pygame "No module called pygame.base"