What do you mean exactly by “name”?
There are 3 kinds of identifiers that are used by CSS:
the class CSS name, like label, image, button. It’s the same for all widgets of the same type. You can get it with Gtk.WidgetClass.get_css_name. It’s hardcoded at widget class declaration, can’t be changed.
the widget name, shall be unique, get it with Gtk.Widget.get_name. In CSS you can refer it by prefixing a sharp symbol, like #mywidgetname.
the CSS classes, you can assign any number of them to any number of widgets, refer them with a dot prefix like .mycustomclass in CSS. You can check if a class is applied with Gtk.Widget.has_css_class.
The CSS name is the equivalent of p or div in HTML: it’s meant to select all widgets when styling.
The widget’s name is meant as a debugging tool, as GTK does not enforce uniqueness.
If you’re traversing a widget tree to find specific widgets you’re also doing something fairly inefficient; if you need quick access to specific widgets, keep a reference to them into a state object, or, if you’re subclassing a type, keep a reference in the instance data structure.