Forum Archive

Custom Button Image Returns White Canvas?

RocketBlaster05

Hello! I have a button on my menu that I wish to change the background image of. I have tried several pictures, including one that already works and is presented elsewhere on screen. All pictures return a blank white canvas when presented on screen. Is it possible to make custom button images? Here is the code:
class Menu(Scene): def __init__(self): self.background_color = '#4fb357' self.mm = ui.load_view('MainMenu') self.mm['imageview1'].image = ui.Image('companylogo.PNG') #works, presents image self.mm['button5'].image = ui.Image('companylogo.PNG')#doesnt work, presents white square self.changetotals() # ignore this self.mm.present('fullscreen', hide_title_bar=True)

cvp

@RocketBlaster05 try

 image = ui.Image.named('path').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
RocketBlaster05

@cvp said:

ui.Image.named('path').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)

Worked like a charm lol

lissakathi

Hy! Hope you're fine. Is it shows an 404 error? Or its my technical issue? https://apikay.com/

cvp

if you want to display an image from an url, try this little script

import ui
import requests

v = ui.ImageView()
url = 'https://upload.wikimedia.org/wikipedia/commons/4/4b/What_Is_URL.jpg'
v.image = ui.Image.from_data(requests.get(url).content)
wi,hi = v.image.size
w = 400
h = w * hi/wi
v.frame = (0,0,w,h)
v.present('sheet')