Python上的无效语法:“ def方法(self,(x,y)):”

时间:2019-06-12 05:29:29

标签: python object methods syntax invalidation

当我尝试运行Python时,它说语法无效,并向我显示了这段代码:def drawTitle(self, (x, y)):。更具体地说,错误来自(x , y)括号中。我正在使用python版本3.7。

# writes and positions the title 
def drawTitle(self, (x, y)):

    font = pygame.font.Font("Chalkduster.ttf",80)
    textDisplay = font.render("Checkers", True, red)
    textRect = textDisplay.get_rect()
    textRect.center = (x, y)
    self.startWnd.blit(textDisplay, textRect)

代码未执行并显示警报:“无效语法”

1 个答案:

答案 0 :(得分:0)

您可以编写如下代码:

def drawTitle(self, t):
   # x, y = t
   font = pygame.font.Font("Chalkduster.ttf",80)
   textDisplay = font.render("Checkers", True, red)
   textRect = textDisplay.get_rect()
   textRect.center = t
   self.startWnd.blit(textDisplay, textRect)

# call: drawTitle((10,12))