Forum Archive

Set Button image programmatically

ywangd

This could be a dumb question. But I had no success on setting a button's image programmatically, i.e. NOT using UI designer.

I tried following code

b = ui.Button(image=ui.Image(os.path.expanduser('~/Pythonista.app/Textures/ionicons-close-circled-24.png')))

and

b = ui.Button()
b.image = ui.Image(os.path.expanduser('~/Pythonista.app/Textures/ionicons-close-circled-24.png'))

None of above codes works.

Any advices?

ccc

Try:

b.image = ui.Image.named('ionicons-close-circled-24.png')

See: http://omz-forums.appspot.com/pythonista/post/6449019224064000

ywangd

Thanks!
Just realised it is in fact documented ...