【问题标题】:Why im a getting this PEP-warning?为什么我会收到此 PEP 警告?
【发布时间】:2020-11-13 10:26:35
【问题描述】:

我在我的 Pygame 中收到了这些 pep-warning:

Expected type 'bool', got 'int' instead

它们都与这样的变量相关,我为我的文本定义字体等:

welcome = welcome_font.render("Welcome to mosquito hunt! ", 1, (0, 0, 0))

有人知道为什么以及如何解决吗?

【问题讨论】:

  • render 的第二个参数是 antialias,大概应该是布尔值 (True) 而不是整数 (1),虽然我猜它会起作用任何truth-y value都可以。

标签: pygame pep


【解决方案1】:

render 的第二个参数是布尔值并控制锯齿。它必须是True 而不是1

welcome = welcome_font.render('text', True, (0, 0, 0))

【讨论】:

  • 谢谢,就是这样
【解决方案2】:

有谁知道原因

您收到警告“预期类型为 'bool',而得到 'int'”,因为在某个地方,您正在传递一个 int,而 Python 期望的是 bool

以及如何解决?

在您传递int 而Python 期待bool 的地方,传递bool 而不是int

最有可能的地方在这里:

welcome = welcome_font.render("Welcome to mosquito hunt! ", 1, (0, 0, 0))
#                                                           ↑

The documentation for pygame.font.Font.render(text, antialias, color, background=None) -> Surface 说:

antialias 参数是一个布尔值:如果为 true,则字符将具有平滑的边缘。

因此,调用的第二个参数应该是布尔值,即它应该是TrueFalse

welcome = welcome_font.render("Welcome to mosquito hunt! ", True, (0, 0, 0))
#                                                           ↑↑↑↑

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多