Forum Archive

Resize ui.Image for button

rb

What’s the simplest way to be able to programmatically resize a ui.Image generated from a jpg file for a button background image?
Can I do it with imageContext? Or is PIL the way to go?

JonB

You don't have to resize it, unless you are after something specific.

Try setting the button content_mode =

ui.CONTENT_SCALE_TO_FILL
Or

ui.CONTENT_SCALE_ASPECT_FIT
Or
ui.CONTENT_SCALE_ASPECT_FILL

My memory is a bit fuzzy, but you might need to access the objc instance, then access subviews to get the hidden imageview which is the background image -- then set contentMode on that UIImageView...

rb

Thanks that’s done it and is a lot easier.
I used :
button. content_mode=ui.CONTENT_SCALE_ASPECT_FIT
So seems to work ok without objC.
Thanks!

MustaphaBen

Guys How to make a datepicker plzzzz I am a beginner on pythonista ui
It says The program : AttributeError: 'NoneType' object has no attribute 'text'

def Getdate(sender):
    date = sender.superview['datepicker1']
    year = 'date.year'
    month = 'date.month'
    day = 'date.day'
    datepicker1 = date['label1']. = month
JonB

Well, it is important to look at the traceback, and try to understand what it is telling you.

AttributeError 'NoneType' has no attribute .text means you tried to access a .text attribute on an object which is None.

So, if you look at where you try to access .text, you will see it is date['label1'] -- so for some reason, that lookup is returning None. That must mean there is no subview named label1 within the view you are accessing.

Since you didn't provide the contents of your pyui or code that creates your view, it is hard to debug remotely. You can rename your .pyui to .json, and copy/paste to the forum. Common mistakes include:
1) If you have views that have subviews that have othe subviews, you might be referring to a label1 which is a subview of a different subview, not the date subview.
2) you may have spelled the name wrong.
3) maybe you were copying code from the forums, but you haven't actually created the same view structure. This code seems to expect a button within the main view, the main view has a subview called datepicker, and the datepicker view has a subview called label1. Is that what you intended? Or maybe you meant sender.superview['label1'] ?

Also, as a suggestion, you should usually create a new post, rather than replying to someone else's post when you have an unrelated question.