This question already has an answer here:
I want to see
Display Manager name (Gnome, KDE etc.) via python or bash script. Is there any command for it as
uname? (I try fedora and Debian)
As @eppesuig has said, the environment variable
But that doesn't mean it is the only – or even normal – Desktop environment in use on that system. I usually use GNOME3, but sometimes I boot into KDE or Enlightenment.
If the point of this is to select a desktop-specific GUI package for installation, this really should be used to suggest a default option rather than making a firm decision. If I happened to be running KDE when I installed your app, I would be disappointed to discover I had only installed a QT interface if a GTK interface was available.