Try the following improved code, to get “active” on the first item:
<?php
$product_cats = get_terms([
'taxonomy' => 'product_cat',
'hide_empty' => true,
'parent' => 0,
'fields' => 'names' // Term names
]);
foreach ( $product_cats as $key => $parent_term_name ) {
printf( '<button class="tablinks %s" onclick="%s">%s</button>',
$key === 0 ? esc_attr( 'active' ) : '',
"myFunction(event,'{$parent_term_name}')",
$parent_term_name
);
}
?>