Suppress "DeprecationWarning: Gtk.some.widget is deprecated"

I’m using a couple of GTK4 widgets which are deprecated. I would prefer to use alternatives, but they are deprecated by Flatpak, so I’m stuck with it. Obviously I need to keep an eye on the situation in case a future version abandons them
When I run the app in a terminal I get 3 warnings, which is quite a lot of text. This clutters the screen and makes it harder for me to see real errors. Worse, it would make it very confusing for a user who was trying to spot an error and report it to me.

Is there a GTK4 statement I can put in my application to suppress these warnings?
[Edited to make it clear that it should be a GTK4 statement within the program]

You could try to use the G_ENABLE_DIAGNOSTIC environment variable:

$ G_ENABLE_DIAGNOSTIC=0 ./my_program

I used G_ENABLE_DIAGNOSTIC=1 in 2020 when upgrading a project from GTK 3 to 4.

1 Like

I imagine that would work, but I should have said that I wanted to put a GTK4 command in the program. I’ll edit my original post to make that clear.

There no longer seems to be an option in GTK4, so I’ll do it in Python:

warnings.filterwarnings(“ignore”, category=DeprecationWarning)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.