Creating a Button

Creating a button in zero-true is very easy. It’s as simple as

import zero-true as zt
button=zt.Button(id=’btn’)

Button Values

Buttons return True when clicked and False otherwise. There is no need to write callbacks, simply reference buttons as follows.

if button.value==True:	print("hello")else:	print("goodbye")

Button Use Cases

Buttons have a ton of potential use cases in zero-true. The example above uses a button to toggle different printed statements but logic can be used to render more complicated layouts. One of the more common patterns for using buttons in zero-true are gating expensive computations, for example:

import zero_true as zt 
import time 

def expensive_computation():
	time.sleep(30)

if button.value==True:
expensive_computation()

else:
print("Press Button to Run Expensive Computation")	

Another use case for buttons in zero-true is getting user confirmation before submitting a form. In the example below we save feedback that a user submits in a text area under a .txt file under their name.

import zero_true as zt

#function to write feedback to a file under someone's name
def write_feedback(name,text):
	with open(name+'.txt','w+') as file:
		file.write(text)

#name input
name_input = zt.TextInput(id='txt_i',label='Write you name')
text_area = zt.TextArea(id='txt_a',label='Write  your feedback here')

#submission button
button=zt.Button(id='btn', label= 'Submit you feedback')

if button.value==True and name_input.value:
write_feedback(name_input.value, text_area.value)

Customizing your button

You can also add different colors and labels to your button to make things more interesting. Feel free to play around with all the attributes in the documentation.