有没有办法在 StaticText 中使用整数作为标签

Is there a way to use integers as label in StaticText

我正在用 wxpython 制作游戏,我想在每次单击按钮时计算结果,所以我首先在屏幕上创建结果,用 StaticText,然后当单击任何按钮,我想将 (+1) 添加到结果中。

但我的问题是我不能在 StaticText 中使用整数作为标签,然后我也不能使用 SetLabel 来设置新结果。

示例:

# Error
self.answers_count_num = wx.StaticText(self.panel, pos=(645, 50), label=0)

def answers_count(self, event):
     result = int(self.answers_count_num.GetLabel()) + 1
     self.answers_count_num.SetLabel(result)

有没有办法在 StaticText 中使用整数?

要使用整数作为wx.StaticText对象的标签,您首先需要将它们转换为字符串。喜欢:

# Error
self.answers_count_num = wx.StaticText(self.panel, pos=(645, 50), label=str(0))

def answers_count(self, event):
    result = str(int(self.answers_count_num.GetLabel()) + 1)
    self.answers_count_num.SetLabel(result)