尝试为我的一个项目创建GUI并不断带回此错误?

时间:2020-07-05 22:03:36

标签: python user-interface pygame

使用Python中的回溯功能来开发Sudoku求解器并为其构建GUI,但是它不断出现这三个错误:

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.
  pygame.draw.line(win, (0,0,0), (0, i*gap), (self.width, i*gap), thick)

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.
  pygame.draw.line(win, (0, 0, 0), (i * gap, 0), (i * gap, self.height), thick)

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.
  win.blit(text, (x + (gap/2 - text.get_width()/2), y + (gap/2 - text.get_height()/2)))

我该如何解决问题?

1 个答案:

答案 0 :(得分:0)

您要传递的某些参数可能是float。执行int(var)。例如,

pygame.draw.line(win, (0, 0, 0), int(i * gap, 0), int(i * gap, self.height), thick)

在python中,您可以与运算符//进行除法以将int应用于结果。因此,您可以执行以下操作: win.blit(text, (x + (gap//2 - text.get_width()//2), y + (gap//2 - text.get_height()//2)))