0

Just a small question. I have a class that does something and handles strings. I have an active class that has a button which when pressed closes the screen and deactivates the class at the same time. I would like the class to return the strings it has been handling to variables that are outside the class itself., but I am not sure how to do this.

    class InputBox:
       def __init__(self, x, y, w, h, text=''):
           #... Instructions for defining the class.
       def Otherinstructions():
           #... Other instructions
       def returnVar(): # The function to return text externally.
           return InputBox.text

     NewVar = '' # I would like the class to return the string to this variable.

Thank you. I just want to find out the most effective way.

JayRoy
  • 105
  • 6

1 Answers1

0
box = InputBox(<your data>)
NewVar = box.returnVar()

Although you should follow the style convention where methods and variables begin with a lowercase character. For future reference, the returnVar() method is called a getter.

Michael Bianconi
  • 5,072
  • 1
  • 10
  • 25
  • It should be something like `new_var`, `return_var()` and `other_instructions()`, according to PEP8. See: [Function Naming Conventions](https://www.python.org/dev/peps/pep-0008/#id45) – Filip Feb 14 '20 at 14:56