Python + GTK - 如何抑制警告

标签 python gtk pygtk

当我启动我的 python 程序时,终端充满了:

rcGUI.py:331: Warning: Attempt to add property GtkSettings::gtk-label-select-on-focus after class was initialised
label1 = gtk.Label("Current tools configured:")
rcGUI.py:286: Warning: Attempt to add property GtkSettings::gtk-scrolled-window-placement after class was initialised
scroll_window = gtk.ScrolledWindow()
rcGUI.py:291: DeprecationWarning: use gtk.TreeView
infoList = gtk.CList(2, ["Tool" , "Version"])
rcGUI.py:291: Warning: Attempt to add property GtkSettings::gtk-button-images after class was initialised
infoList = gtk.CList(2, ["Tool" , "Version"])
rcGUI.py:217: Warning: Attempt to add property GtkSettings::gtk-can-change-accels after class was initialised
toolCombo = gtk.combo_box_entry_new_text()
rcGUI.py:217: Warning: Attempt to add property GtkSettings::gtk-menu-popup-delay after class was initialised
toolCombo = gtk.combo_box_entry_new_text()
rcGUI.py:217: Warning: Attempt to add property GtkSettings::gtk-menu-popdown-delay after class was initialised
toolCombo = gtk.combo_box_entry_new_text()
rcGUI.py:217: Warning: Attempt to add property GtkSettings::gtk-entry-select-on-focus after class was initialised
toolCombo = gtk.combo_box_entry_new_text()
rcGUI.py:217: Warning: Attempt to add property GtkSettings::gtk-entry-password-hint-timeout after class was initialised
toolCombo = gtk.combo_box_entry_new_text()

有趣的是,我在 KDE 中运行它的用户不会收到所有这些警告(弃用警告除外),但 GNOME 中的用户会收到。所以我认为最简单的方法是抑制所有这些警告。我只是还没能找到方法。

最佳答案

import warnings
warnings.filterwarnings("ignore")

取消过滤:

warnings.filterwarnings("default")

关于Python + GTK - 如何抑制警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20708657/

相关文章:

python - 如何使最后一个 gtk.TreeView 列可调整大小?

python - 使用 distutils,其中 swig 接口(interface)文件位于 src 文件夹中

初始化派生类和抽象类时出现python错误

python:循环每个键有多个值的字典

python - 在没有 X11 的情况下使用 Python Gtk3 绑定(bind)

gtk - 在 gtk.SpinButton 中显示前导零

python - Python中多对的相同操作

macos - 在Mac上安装ige-mac-integration时出错

c - 我需要释放 GTK 中的弹出菜单吗?

gtk - Cairo.ImageSurface 到 Gdk.Pixbuf?