Robert Y. Button, an austere, pokerfaced country lawyer whose unyielding opposition to school desegregation helped make him twice attorney general of Virginia, died yesterday of a heart attack at his home in Culpeper.

He was 77.

A loyal lieutenant in the old Byrd Democratic organization which long ruled Virginia. Button served 15 years in the state senate before winning election in 1961 to the first of his two terms as attorney general.

As a member of the State Board of Education from 1945 to 1961, Button maintained strong support for the Byrd organization's policy of public parsimony toward public schools. With other conservative Democrats he voted to defy the 1954 U.S. Supreme Court decision ordering desegregation of public schools, and later championed the "massive resistance" policy through which the state closed some white schools rather than permit the enrollment of black pupils.

In 1961 when the bitter fight over 'massive resistance' issue had divided the State, Button received the blessing of the late Sen. Harry F. Byrd Sr. to run for the state's top legal post. His running mates were Albertis S. Harrison, now a justice of the Virginia Supreme Court, who ran for governor, and now Gov. Mills E. Godwin Jr., who ran for lieutenant governor.

Their election was viewed nationwide as a signal that the winds of political change sweeping much of the rest of the South had yet to be felt in Virginia.

As attorney general. Button was largely a caretaker officeholder, continuing the state's tradition of parceling out major litigation to private law firms.

The efforts of his office were largely concentrated in answering routine legal questions and defending laws like Virginia's anti-miscegenation statue against court attack.

Button first entered politics in 1933 as Culpeper County campaign manager for the late Gov. George C. Peery and was elected to the State Senate in 1946 representing Culpeper, Fauquer and Loudoun counties.

Though a taciturn legislator who seldom addressed the Senate. Button rose to membership on several key Senate committees and to chairman of the Senate Welfare Committee.

After his retirement from office in 1969. Button returned to his cattle farm and private law practice in Culpeper.