你可以使用 Gtk.main_level() 函数: Gtk.main_level() Returns: the nesting level of the current invocation of the main loop 换句话说,返回值为 0 表示没有主循环在运行。