I want to have a button that has a different shape than a rectangle. I think ui.Path is the way to go but I am having trouble implementing it. I have code for a simple button press. Could I get some help changing it so the button changes to say a hexagon?
import ui
# Define variables
btn_counter=-1 # button pressed count
btn_color=['red','magenta','blue','green','yellow','cyan'] # button colours
btn_txt=['click again','click one more time','have another go','go again please', 'one last press','finally'] # button text when pressed
# Define functions
# What button1 does when tapped
def button1_tapped(sender):
global btn_counter # count number of times the button is pressed
btn_counter+=1
if btn_counter<=5: # cycle through button colours
sender.title = btn_txt[btn_counter] # change button text when pressed
sender.size_to_fit() # adjust button size to fit new text exactly
button1.width=1.5*button1.width # change button width
button1.height=2*button1.height # change button height
button1.bg_color = btn_color[btn_counter] # change button colour when tapped
else:
view.remove_subview(button1) # remove button
some_box.title = 'thank you for your time' # change box text
some_box.size_to_fit() # change box size to fit new text exactly
some_box.frame=(view.width*0.38,view.height*0.45,1.1*some_box.width,2*some_box.height) # change box location and size
# Create display, further details see theBackground.py
view=ui.View()
view.present('fullscreen', hide_title_bar=True)
view.background_color = (214/255,12/255,140/255)
# Create button
button1 = ui.Button(title='Click me') # initial button text
button1.center = (view.width*0.38, view.height*0.45) # Button initial position
button1.border_width = 5 # give button a border
#button1.size_to_fit() # fit button around text exactly
button1.width = view.width*0.3 # button width
button1.height = view.height*0.2 # button height
button1.bg_color = (.3,.31,.32) # button colour (.3,.31,.32,0) fof transparent
button1.font = ('Chalkduster', 30) # button font type and size
button1.tint_color=(1,1,1) # button font colour
button1.action = button1_tapped # needed for when button pressed
view.add_subview(button1) # display button
# Include non-interactive box
some_box = ui.Label(
text='This is not a button', # box text
background_color=(95/255,96/255,98/255), # box colour
text_color='white', # box text colour
alignment=ui.ALIGN_CENTER, # text alignment in box
number_of_lines=0, # number of lines used in box
frame=(10, 10, view.width-20, 100)) # box position (10 in, 10 down, view.width-20 wide, 100 high)
some_box.font=('HoeflerText-BlackItalic', 40) # box font type and size
view.add_subview(some_box) # show box