Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
What's wrong with this?
-
This is a program I wrote which is supposed to change a button's image from a smiley face to an ant when the face is touched. When I ran it, it did change, but also kept the face image. How do I get it so that it gets rid of the face when the image is touched?
Here's the code:
#coding: utf-8 import ui def pressed (sender): sender.tint_color = 1.00, 0.00, 0.00 button1.background_image = ui.Image.named('Ant') view = ui.View() view.name = "tic tac toe" view.background_color = 0.90, 0.90, 0.90 view.present("sheet") button1 = ui.Button(title = "😄") button1.flex = "LRTB" button1.action = pressed view.add_subview(button1) button1.center = (view.width *0.5,view.height *0.5) button1.font = ('AmericanTypewriter-Condensed', 60) button1.size_to_fit()
Thanks!
-
You're using two different types of button "decoration" here - the first one, the smiley face, is technically text, a string containing an Emoji character. The second one, the ant, is technically an image. This leads to the two types overlapping instead of replacing each other.
It would probably be easiest to have the
pressed
method set the button text to the ant emoji (🐜), although you could of course also use the image version of the smiley face initially. Both methods work just fine. -
Thanks!