鱼C论坛

 找回密码
 立即注册
查看: 2891|回复: 3

pygame上的字体颜色报错

[复制链接]
发表于 2022-8-27 21:13:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import pygame
import sys
#初始化pygame
pygame.init()
size = width,height = 400,600
position = 0

#设置背景板
screen = pygame.display.set_mode(size)
#窗口标题
pygame.display.set_caption("监测事件")
#背景色填充
bg = (0,0,0)

screen.fill(bg)
font = pygame.font.Font(None,20)#字体
line_height = font.get_linesize()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        font.render(str(event),True,(0, 255, 0),(0,position))#此处报错
        position += line_height

        if position> height:
            position = 0
            screen.fill(bg)
        pygame.display.flip()#清屏
小甲鱼课上的源码,一直报错,ValueError: invalid color argument
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-8-27 22:04:26 | 显示全部楼层
pygame模块,你Python里应该没有下载这个模块
win+r在弹出的窗口输入cmd打开命令行输pip3 install pygame 下载好就可以了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-8-27 22:11:24 From FishC Mobile | 显示全部楼层
kaobiel 发表于 2022-8-27 22:04
pygame模块,你Python里应该没有下载这个模块
win+r在弹出的窗口输入cmd打开命令行输pip3 install pygame  ...

pycharm中已经安装
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-8-28 10:07:38 | 显示全部楼层
Tihool 发表于 2022-8-27 22:11
pycharm中已经安装
  1. import pygame
  2. import sys
  3. #初始化pygame
  4. pygame.init()
  5. size = width,height = 400,600
  6. position = 0

  7. #设置背景板
  8. screen = pygame.display.set_mode(size)
  9. #窗口标题
  10. pygame.display.set_caption("监测事件")
  11. #背景色填充
  12. bg = (0,0,0)

  13. screen.fill(bg)
  14. font = pygame.font.Font(None,20)#字体
  15. line_height = font.get_linesize()

  16. while 1:
  17.     for event in pygame.event.get():
  18.         if event.type == pygame.QUIT:
  19.             sys.exit()
  20.         screen.blit(font.render(str(event),True,(0, 255, 0)),(0,position)) #把两个参数传到一个里面了!
  21.         position += line_height

  22.         if position> height:
  23.             position = 0
  24.             screen.fill(bg)
  25.         pygame.display.flip()#清屏
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-27 05:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表