\documentclass{article}

\usepackage{ifthen}

\newlength{\boxbreite}
\newcommand{\textbox}[2][]{
  \settowidth{\boxbreite}{#1}
  %% ???
  \ifthenelse{\lengthtest{\boxbreite} = 0pt}{\settowidth{\boxbreite}{#2}}{}

  \framebox[\boxbreite]{#2}
}

\begin{document}

\textbox{Hallo Welt}
\textbox[MMMMMMMMMMMMMMMM]{Hallo Welt}
\textbox{Hallo Welt}

\end{document}
