繁体   English   中英

当我运行我的代码时会弹出一个警告。 我不知道如何解决

[英]A warning pops up when I run my code. I don't know how to solve it

因此,我编写的代码运行良好,但不断弹出警告。 我不知道这意味着什么以及如何处理它。 警告如下:

Warning (from warnings module):
  File "C:/Users/LENOVO/Desktop/GROOT!/ch.py", line 41
    win.blit(char, (x, y))
DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

我不知道是否需要更改代码中的某些内容。 请告诉我我需要做什么。

警告意味着x和/或y具有浮点值,但blit() (以及 PyGame 中的其他函数)需要 integer 值。 你可以使用int(x), int(y)来改变它

win.blit(char, (int(x), int(y)))

警告还通知这次它会自动将其转换为 integer 但在下一个 PyGame 的版本中它可能不会这样做,最好手动使用int()

您可以使用以下方式静音此警告

import warnings
warnings.filterwarnings('ignore', category=Warning)

或者您使用int(x), int(y)将 x 和 y 转换为 int

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM