This looks like something that should be doable via code, but isn't (at least not yet) - you may want to file an issue on the godot github page about it. That said, there are a few things you can try.
Depending on how many different background colors you want to have available, you can either create them in advance and save them as resources (ie, multiple .tres or .xml stylebox files, each with their own bg color) or instance them in code:
# From an external resource - I haven't tested but this should work:
var new_style = load("path/to/bada55-stylebox.tres")
# In code:
var new_style = StyleBoxFlat.new()
new_style.set_bg_color(Color("#bada55"))
In theory, you should then be able to set that on the panel with add_style_override
- but for some reason that isn't working in this scenario. So you can get the desired effect with this instead:
var panel = get_node("Panel")
panel.set('custom_styles/panel', new_style)
This actually works out well, because now that you've defined new_style
, you don't have to keep instancing new styleboxes; you can update that one at any time and the panel will reflect the change.
new_style.set_bg_color(Color("#bada55")) # green
panel.set('custom_styles/panel', new_style) # panel is now green
new_style.set_bg_color(Color("#ffaa00") # panel is now orange
(Note that in this example, you'd only ever see the panel as orange; if you wanted to see it green, then orange, you'd have to put in a timeout or something in between lines 2 and 3.)