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

How do I call print1 within the object?

I tried doing at XXXXXX

  1. self.print1()
  2. self.print1(self)
  3. print1(self)
  4. primt1()
  5. c = AlarmBox()
  6. c.print1()

in java you can do:

this.print1() or print1() !

1
  • did you get an error message? Commented Jun 14, 2013 at 4:56

3 Answers 3

2

You can do this in python as well, but you need to execute your code at some point:

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 is not a place to execute code, it's a place to define class members variables and methods.

Sign up to request clarification or add additional context in comments.

Comments

1

At the outermost level (same indent level as class AlarmBox, you can declare code that is not part of that class:

c = AlarmBox()
c.print1()

The problem was that your code at XXXXXX was within the class.

Comments

-1

Use constructor

def __init__(self):
    self.print1()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.