Forum Archive

Imageview clicks/touch

Phuket2

Would I be right in saying the easiest way to get an imageivew to respond to clicks is just to put a button on top of the imageview and use the buttons action? I have been trying to find a simple way to get an imageview to respond to a tap/click, with no success. then the obvious came to me about overlaying a button. It works,but would love to hear if there is a simple way to get the imageview to call a function on a click/touch. Thanks, mr newbie

brumm

Do you need an imageview? Why not use a button.background_image?

# coding: utf-8

import ui

class ButtonTest(object):

    def __init__(self):
        self.view = ui.load_view('ButtonTest')
        self.button = self.view['button1']
        self.button.background_image = ui.Image.named("image000.jpg")
        self.view.present('full_screen')

ButtonTest()
Phuket2

@brumm, thank you. Great solution. Not sure it should be a great solution, but in this case it is. I tried in my code already, and a far better solution.

Phuket2

Oh, I just did like this

    v['my_button'].background_image = get_image('_indra_logo.png')

Just a simple example, but it works.

Phuket2

Oops, my get_image() func looks like this

__SWATCH_PATH__ = os.path.expanduser('~/Documents/Images/')


    def get_image(file_name):
    return ui.Image.named(__SWATCH_PATH__  + file_name)