[guided]The definition of weak compactness has several equivalent forms. We use the tree-property form: after proving that $\kappa$ is inaccessible, it remains to show that every $\kappa$-tree has a cofinal branch.
Let $(T,<_{T})$ be an arbitrary $\kappa$-tree. Let $\operatorname{ht}_{T}:T\to\kappa$ be its height map, and for each $\alpha<\kappa$ define
\begin{align*}
T_\alpha=\{t\in T:\operatorname{ht}_{T}(t)=\alpha\}.
\end{align*}
By definition of a $\kappa$-tree, $|T_\alpha|<\kappa$ for every $\alpha<\kappa$, and the set of predecessors of each node is well-ordered by $<_{T}$.
We replace $T$ by an isomorphic copy whose nodes are ordinal-coded level by level: each node on level $\alpha$ is a pair $(\alpha,\xi)$ with $\xi<\mu_\alpha$ for some $\mu_\alpha<\kappa$, and the order and height data are coded by subsets of $\kappa$. This does not change whether $T$ has a cofinal branch. The reason this normalization matters is that the ultrapower embedding constructed from the measure has critical point $\kappa$, so it fixes every ordinal below $\kappa$ and therefore fixes each node, each order comparison, and each height assertion involving original levels $T_\alpha$ with $\alpha<\kappa$.
Let $V$ denote the universe of sets, viewed as the domain of the ultrapower construction. Since $U$ is $\kappa$-complete and $\kappa$ is uncountable, $U$ is countably complete; the standard ultrapower theorem for countably complete ultrafilters gives that the ultrapower by $U$ is well-founded. Its Mostowski collapse gives a transitive class $M$ and an elementary embedding
\begin{align*}
j:V\to M.
\end{align*}
The critical point $\operatorname{crit}(j)$ is the least ordinal moved by $j$. Nonprincipality makes $j$ move $\kappa$, while $\kappa$-completeness makes $j$ fix every ordinal below $\kappa$; hence $\operatorname{crit}(j)=\kappa$, so $j(\alpha)=\alpha$ for all $\alpha<\kappa$ and $j(\kappa)>\kappa$.
By elementarity, $j(T)$ is a $j(\kappa)$-tree in $M$ with tree order $<_{j(T)}=j(<_{T})$. Since $\kappa<j(\kappa)$, the level
\begin{align*}
j(T)_\kappa=\{x\in j(T):\operatorname{ht}_{j(T)}(x)=\kappa\}
\end{align*}
is nonempty in $M$. Choose $x\in j(T)_\kappa$.
For each $\alpha<\kappa$, the predecessor set of $x$ in $j(T)$ is well-ordered by $<_{j(T)}$ with order type $\kappa$, so there is a unique node $b_\alpha\in j(T)_\alpha$ such that $b_\alpha<_{j(T)}x$. Because $j$ fixes every ordinal and every coded node on levels below $\kappa$, the $\alpha$th level of $j(T)$ is exactly the original level $T_\alpha$ for each $\alpha<\kappa$. Thus $b_\alpha\in T_\alpha$.
Define
\begin{align*}
B=\{b_\alpha:\alpha<\kappa\}.
\end{align*}
This set meets every level of $T$. If $\alpha<\beta<\kappa$, then $b_\alpha$ and $b_\beta$ are both predecessors of $x$ in $j(T)$, and the predecessor set of a node is linearly ordered by the tree order. Since their heights are $\alpha$ and $\beta$, respectively, we have $b_\alpha<_{j(T)}b_\beta$. On levels below $\kappa$, $<_{j(T)}$ agrees with $<_{T}$, so $b_\alpha<_{T}b_\beta$. Therefore $B$ is a chain meeting every level of $T$, hence a cofinal branch through $T$.
Since $T$ was arbitrary, every $\kappa$-tree has a cofinal branch. Together with inaccessibility, the tree-property characterization gives that $\kappa$ is weakly compact.[/guided]