英文:
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
以下部分已翻译:
以下部分已翻译:
def delete_query(self, widget, data):
selected_item = self.dropdown.get_selected_item()
item_to_delete = selected_item.iid
dialog = Gtk.AlertDialog()
dialog.set_message("注意")
dialog.set_detail("您即将执行无法撤销的操作。是否继续?")
dialog.set_modal(True)
dialog.set_buttons(["取消", "确定"])
dialog.choose(self, None, self.delete_perform, item_to_delete)
def delete_perform(self, source_obj, async_res, item_to_delete):
result = source_obj.choose_finish(async_res)
if result == 1:
# 删除项目 item_to_delete
英文:
The following works:
def delete_query(self, widget, data):
selected_item = self.dropdown.get_selected_item()
item_to_delete = selected_item.iid
dialog = Gtk.AlertDialog()
dialog.set_message("Caution")
dialog.set_detail("You are about to take an action that cannot be undone. Proceed?")
dialog.set_modal(True)
dialog.set_buttons(["Cancel", "OK"])
dialog.choose(self, None, self.delete_perform, item_to_delete)
def delete_perform(self, source_obj, async_res, item_to_delete):
result = source_obj.choose_finish(async_res)
if result == 1:
< delete item_to_delete >
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论