# Dynamic GUI problem

I'm fairly new to Mathematica and currently making a simple GUI.

I'd like to work with dropdown menus and I'd like to dynamically change the possibilites of those menus depending on what's selected in the previous menu.

Using a ton of If-functions seemed impractical to me and so I ended up using the Piecewise-function instead (which might be stupid as well).

   (*Dynamische Eingabefeld-Abhängigkeiten*)
Dynamic[Piecewise[{
{diminput=Column[{"Länge: "InputField[Dynamic[l],Number], "Breite: "InputField[Dynamic[b],Number]}], form=="Viereck"},
{diminput=Column[{"Länge: "InputField[Dynamic[l],Number], "Breite: "InputField[Dynamic[b],Number], "Höhe: "InputField[Dynamic[h],Number]}], form=="Quader"},
}]]

(*GUI Input-Oberfläche*)
Panel[
Grid[{
{Style["2D oder 3D mesh?", Bold]},
{Style["Geometrische Form:", Bold], Style["Dimensionen [mm] :", Bold]},
}]]


The code works as intended, however I cannot put a ";" behind the Piecewise-Functions. Once I do that it stops working. At the same time, having the evaluation of those functions permanently shown kinda ruins the look.

My questions would be:

1) is there a smarter way to hoave dependent drop down menus?

2) is there a way to surpress the output of the Piecewise-Functions without having them to stop working?

0) Piecewise is more for math applications. I'd use Switch as more readable here: Switch[method, "2D", {"Viereck", "Kreis"}, "3D", {"Quader", "Zyllinder"}] etc.

2) Correct, with your approach you need to keep first two Dynamic visible. See Dynamic and tutorials linked at the bottom of its documentation. Other ways to react to changes of certain variable is to use DynamicWrapper or the second argument of Dynamic

DynamicWrapper[ controller[Dynamic[var]], var2 = something[var], TrackedSymbols :> {var}]

(*or*)

controller[Dynamic[var, {Automatic, (var2 = something[var])&}]]


See docs for more details.

1) Here is my implementation, and I don't really use any of methods mentioned above. I just make form menu dynamic based on method value instead of having an additional forminput variable.

DynamicModule[{method = "2D", forms, form = "Viereck", dims, l, b, r,
h},
Panel[
Grid[{
{Style["2D oder 3D mesh?", Bold]},
{Style["Geometrische Form:", Bold], Style["Dimensionen [mm] :", Bold]},
Dynamic[Grid[dims[form], Alignment -> {Left, Center}]]}
}]
],
Initialization :> (
forms[method_] :=
Switch[method, "2D", {"Viereck", "Kreis"},

dims[form_] := Switch[form,
"Viereck", {{"Länge:",
InputField[Dynamic[l], Number]}, {"Breite:",
InputField[Dynamic[b], Number]}},
InputField[Dynamic[l], Number]}, {"Breite:",
InputField[Dynamic[b], Number]}, {"Höhe:",
InputField[Dynamic[h], Number]}},

• @p4di here it is mostly for localization of those symbols and also for storing definitions of forms and dims so you can deploy it as cdf and it will work.