from taipy.gui import Gui
from taipy.designer import Page


V = 1
n = 1
# Ideal gas constant
R = 8.314
T = 273.15
P = n*R*T/V

# Calculate Ideal Gas Law and display result
def calculate_ideal_gas_law(state):    
    # Check if the volume is not zero to avoid division by zero
    if V > 0:
        # Calculate pressure: P = nRT / V
        state.P = (state.n * state.R * state.T) / state.V
    else:
        return '--'
    

def on_change(state, var, val):
    if var in ["V", "n", "T"]:
        calculate_ideal_gas_law(state)

page = Page("form.xprjson")
Gui(page).run(design=True)
