pyGtk3对话必须有父母吗?如果是这样,您如何通过脚本调用它们?

时间:2016-07-16 04:28:05

标签: python pygtk gtk3

我可以使用一个调用窗口的脚本,但是当我尝试使用parent = None进行对话时,我得到:

Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

我可以将此映射到哪个父母?我似乎可以将它映射到一个虚拟的父母,但这会导致事情破裂而人们会死吗?

来自http://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#messagedialog的代码,从父窗口调用它...但我希望能够在我运行终端脚本时弹出它。

编辑:有些讨论(并在下面的答案中提供)产生了使用Gtk.Window()作为下面的第一个参数(而不是没有)确实摆脱了消息..

def on_question():
    dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.QUESTION,
        Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")
    dialog.format_secondary_text(
        "And this is the secondary text that explains things.")
    response = dialog.run()
    if response == Gtk.ResponseType.YES:
        print("QUESTION dialog closed by clicking YES button")
    elif response == Gtk.ResponseType.NO:
        print("QUESTION dialog closed by clicking NO button")

    dialog.destroy()

1 个答案:

答案 0 :(得分:2)

我将上述评论作为答案。 您可能在代码中的某处(可能在函数体内)有一个w = Gtk.Window()并将该w传递给on_question:

<script type="text/javascript">

var today = document.getElementById("today_date");
var expired = document.getElementById("passport_expire_date");

function myDIV() {
  if ($today == $expired) {
    document.getElementById("myDiv").style.backgroundColor="#ff4d4d";
  }
}
</script>

def on_question(parent=None):
    dialog = Gtk.MessageDialog(parent, 0, Gtk.MessageType.QUESTION,
        Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")
....
w = Gtk.Window()
on_question(w)

如果这是唯一的问题,它已消失的Gtk消息。