2
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(自我)
  3. 打印1(自己)
  4. primt1()
  5. c = 报警箱()
  6. c.print1()

在java中你可以这样做:

this.print1() 或 print1() !

4

3 回答 3

2

您也可以在 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 不是执行代码的地方,它是定义类成员变量和方法的地方。

于 2013-06-14T04:56:05.223 回答
1

在最外层(与 相同的缩进级别class AlarmBox,您可以声明不属于该类的代码:

c = AlarmBox()
c.print1()

问题是您的代码在XXXXXX课堂上。

于 2013-06-14T04:59:10.830 回答
-1

使用构造函数

def __init__(self):
    self.print1()
于 2013-06-14T05:20:09.807 回答