pyGtk3 对话必须有 parent 吗?如果是这样,您如何从脚本中调用它们?
pyGtk3 Do dialogues have to have a parent? If so, how do you call them from a script?
我可以有一个调用 window 的脚本,但是当我尝试与 parent = None 进行对话时,我得到:
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
我可以将它映射到什么parent?看来我可以把它映射到一个虚拟的 parent,但这会导致事情破裂和人员死亡吗?
来自 http://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#messagedialog 的代码,它是从 parent window 调用的...但我希望能够弹出它,因为我是 运行通过终端脚本。
编辑: 一些探索(并通过下面的答案提供)得出使用 Gtk.Window() 作为下面的第一个参数(而不是 none) 确实删除了消息...
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()
我会把上面的评论作为答案。
您可能在代码中的某处有一个 w = Gtk.Window() (它可能在函数体内)并将该 w 传递给 on_question:
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)
或
def on_question():
dialog = Gtk.MessageDialog(Gtk.Window(), 0, Gtk.MessageType.QUESTION,
Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")
Gtk 消息消失了,如果这是唯一的问题。
我可以有一个调用 window 的脚本,但是当我尝试与 parent = None 进行对话时,我得到:
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
我可以将它映射到什么parent?看来我可以把它映射到一个虚拟的 parent,但这会导致事情破裂和人员死亡吗?
来自 http://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#messagedialog 的代码,它是从 parent window 调用的...但我希望能够弹出它,因为我是 运行通过终端脚本。
编辑: 一些探索(并通过下面的答案提供)得出使用 Gtk.Window() 作为下面的第一个参数(而不是 none) 确实删除了消息...
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()
我会把上面的评论作为答案。 您可能在代码中的某处有一个 w = Gtk.Window() (它可能在函数体内)并将该 w 传递给 on_question:
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)
或
def on_question():
dialog = Gtk.MessageDialog(Gtk.Window(), 0, Gtk.MessageType.QUESTION,
Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")
Gtk 消息消失了,如果这是唯一的问题。