gpt4 book ai didi

Python 方法调用

转载 作者:太空宇宙 更新时间:2023-11-04 03:58:18 26 4
gpt4 key购买 nike

class AlarmBox(Widget):


hour = ["12","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
tensMin = ["0", "1", "2", "3", "4", "5"]
onesMin = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
day = ["AM", "PM"]
txt_inpt = ObjectProperty(None)


def print1(self):
self.txt_inpt.text("HI")

XXXXXXX

如何在对象中调用 print1?

我在 XXXXXX 试过

  1. self.print1()
  2. self.print1(self)
  3. 打印1(自己)
  4. primt1()
  5. c = AlarmBox()
  6. c.print1()

在java中你可以这样做:

this.print1() 或 print1() !

最佳答案

您也可以在 python 中执行此操作,但您需要在某个时候执行您的代码:

class AlarmBox(Widget):


hour = ["12","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
tensMin = ["0", "1", "2", "3", "4", "5"]
onesMin = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
day = ["AM", "PM"]
txt_inpt = ObjectProperty(None)


def print1(self):
self.txt_inpt.text("HI")

# XXXXXXX

def print1_caller(self):
self.print1()

XXXXX不是执行代码的地方,它是定义类成员变量和方法的地方。

关于Python 方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17101316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com