Hi Guys,
I'm new to Python/Pythonista and reading through different material but I'm struggling to find examples of how to get a ui.button to change attributes of a different class object.
I have a basic example of a widget that has an Image View that should present/change a different image when the ui.button is pressed.
The error I get is "ui.button object has no attribute "view"". Obviously it's "ImView" that has the attribute "view" but I just can't seem to work out how to access the "ImView" object via the button action.
I'm sure there may be numerous issues with my beginner code but any general help would be greatly appreciated.
```
import appex, ui
import random
Image_One = ui.Image.named('Image_One.PNG')
Image_Two = ui.Image.named('Image_Two.JPG')
PIC_LIST = [Image_One,Image_Two]
class MyView(ui.View):
def init(self):
self.hue = 0
self.background_color = 'white'
self.add_subview(ImView().view)
self.add_subview(MyHandler().sender)
class ImView(object):
def init(self):
self.view = ui.ImageView()
self.view.frame = (150,0,170,110)
self.view.background_color = 'white'
self.view.border_color = 'black'
self.view.border_width = 1
self.view.image = None
def add_pic(self):
self.view.image = PIC_LIST[random.randint(0,1)]
class MyHandler(object):
def init(self):
self.sender = ui.Button(frame=(0,0,150,110), title='Hit Me', action=ImView.add_pic)
appex.set_widget_view(MyView())```