Problem with displaying alarm menu on a clock

so im trying to create an arduino alarm clock that displays current time and when you press one of 4 buttons it displayes 3 variables that will be altered by plus and minus buttons that i will add later. The issue is that no matter if i press the button or not the variables appear on the screen the moment that minute on the clock changes. Note that variables appear and disappear when i press and unpress normally before the minute number on the clock changes.
at the start of the program


after pressing a button

after the minute number changes. doesnt matter if i press the button before it or after, it wont disappear

and heres the code-

#include <LiquidCrystal_I2C.h>
#include <virtuabotixRTC.h>
#include <Arduino.h>
// Creation of the Real Time Clock Object
LiquidCrystal_I2C lcd(0x27,  16, 2);
virtuabotixRTC myRTC(6, 7, 8);
//constant variables
const int BP1=1;
const int BP2=2;
const int BP3=3;
const int BP4=4;
//variables
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int alarmHour=0;
int alarmMinute=0;
int alarmSecond=0;

void setup(){
  Serial.begin(9600);
  pinMode(BP1, INPUT);
  pinMode(BP2, INPUT);
  pinMode(BP3, INPUT);
  pinMode(BP4, INPUT);
  lcd.init();
  lcd.backlight();  
  // Set the current date, and time in the following format:
  // seconds, minutes, hours, day of the week, day of the month, month, year
  myRTC.setDS1302Time(40, 59, 15, 1, 24, 6, 2024);
}
void loop()  {
 
  // This allows for the update of variables for time or accessing the individual elements.
  myRTC.updateTime();
  // Start printing elements as individuals
  Serial.print("Current Date / Time: ");
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print("  ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);


  // buttons
  buttonState1 = digitalRead(BP1);
  buttonState2 = digitalRead(BP2);
  buttonState3 = digitalRead(BP3);
  buttonState4 = digitalRead(BP4);
   //lcd screen - alarm menu
   if(buttonState1 == HIGH){
      lcd.setCursor(5,1);
      lcd.print(alarmHour);
      lcd.print(":");
      lcd.print(alarmMinute);
      lcd.print(":");
      lcd.print(alarmSecond);
   }
    
      
   
   
    
  //lcd screen - clock
   delay(500);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print(myRTC.hours);
   lcd.print(":");
   lcd.print(myRTC.minutes);
   lcd.print(":");
   lcd.print(myRTC.seconds);
   }

Hold the button displays the alarm.
Release the button and the alarm disappears.

if(buttonState1 == HIGH){
      lcd.setCursor(5,1);
      lcd.print(alarmHour);
      lcd.print(":");
      lcd.print(alarmMinute);
      lcd.print(":");
      lcd.print(alarmSecond);
   } else {
      lcd.setCursor(5,1);
      lcd.print("        ");
  }  

thanks for quick reply, but the outcome is the same ,the variables stay displayed after the minute number changes no matter if i hold the button or not

You are checking only one button.
I have a GPS display on the 20x4 LCD. That works good on mine. Ensure that "else" lcd.print() has enough spaces to overwrite the alarm display.

so i typed a lot of spaces and it didnt work but it does work on the first line of the lcd where the clock is for some reason i even tried having the "menu" at (0,0) so the same space that the clock is and it just overrides the clock and displays the menu so it looks like this:


(the zeros are from the menu and the number "30" is from the seconds counter

ALSO an important thing to notice is that the menu stays for first 9 minutes after 16.00 then appears and disappears for example for 9 seconds of every minute. could it be somehow related to single numbers appearing like from 1 to 9 and working properly when every number on the clock is a 2 digit number?

Try this instead. Use the same on the time using timeBuffer.

char timeBuffer[10];
char alarmBuffer[10];

if(buttonState1 == HIGH){
      lcd.setCursor(5,1);
      sprintf(alarmBuffer,"%02d:%02d:%02d",alarmHour,alarmMinute,alarmSecond);
      lcd.print(alarmBuffer);
   } else {
      lcd.setCursor(5,1);
      lcd.print("          ");
  }  

Edit: How did you wire buttonState1? It's set as INPUT, which floats if nott pulled HIGH or LOW.

I would wire it the other way and use INPUT_PULLUP, then pull the pin LOW with the switch/button.

image
i wired it like this ive seen INPUT_PULLUP being mentioned few times on this similiar projects but i have no idea how it works and how to wire and code it
edit: ive read some things and i kind of see how it works so if i change the INPUT to INPUT_PULLUP with no resistor all i have to do is switch
image
this from HIGH to LOW.

The pin is floating when the button is released.
Either use a resistor to pull the pin LOW when the button is not pressed, or use INPUT_PULLUP and connect the button to the pin and GND rather than V+.

Edit: And change the logic

if(buttonState1 == LOW){