使用Python和Gtk.AlertDialog

huangapple go评论91阅读模式
英文:

Using Gtk.AlertDialog with Python

问题

我尝试将一个用Python编写的旧GTK3项目移植到GTK4,但我在处理Gtk.Dialog的废弃时遇到了问题。具体来说,我找不到如何使用Python从Gtk.AlertDialog中检索用户反馈的示例。有人知道吗?我试图创建一个简单的对话框,让用户如果需要时可以中止操作。谢谢。

英文:

I'm trying to port an old GTK3 project written in Python to GTK4, and I'm having trouble with the deprecation of Gtk.Dialog. Specifically, I can find no example of how to retrieve user feedback from a Gtk.AlertDialog using Python. Does anyone know of one? I am trying to create a small dialog that would simply let the user bail out of an operation if desired. Thanks.

答案1

得分: 2

以下部分已翻译:

  1. 以下部分已翻译
  2. def delete_query(self, widget, data):
  3. selected_item = self.dropdown.get_selected_item()
  4. item_to_delete = selected_item.iid
  5. dialog = Gtk.AlertDialog()
  6. dialog.set_message("注意")
  7. dialog.set_detail("您即将执行无法撤销的操作。是否继续?")
  8. dialog.set_modal(True)
  9. dialog.set_buttons(["取消", "确定"])
  10. dialog.choose(self, None, self.delete_perform, item_to_delete)
  11. def delete_perform(self, source_obj, async_res, item_to_delete):
  12. result = source_obj.choose_finish(async_res)
  13. if result == 1:
  14. # 删除项目 item_to_delete
英文:

The following works:

  1. def delete_query(self, widget, data):
  2. selected_item = self.dropdown.get_selected_item()
  3. item_to_delete = selected_item.iid
  4. dialog = Gtk.AlertDialog()
  5. dialog.set_message("Caution")
  6. dialog.set_detail("You are about to take an action that cannot be undone. Proceed?")
  7. dialog.set_modal(True)
  8. dialog.set_buttons(["Cancel", "OK"])
  9. dialog.choose(self, None, self.delete_perform, item_to_delete)
  10. def delete_perform(self, source_obj, async_res, item_to_delete):
  11. result = source_obj.choose_finish(async_res)
  12. if result == 1:
  13. < delete item_to_delete >

huangapple
  • 本文由 发表于 2023年6月9日 00:16:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定