Skip to main content
 首页 » 编程设计

Python Gtk3,如何向 MessageDialog 插入响应(按钮)

2025年01月19日10java哥

有时我需要向 MessageDialog 插入新的响应(按钮),但我不知道该怎么做。例如 msg_dialog.insert_response(Gtk.STOCK_OK, Gtk.ResponseType.OK, 2)

谢谢

请您参考如下方法:

您要找的方法是Gtk.Dialog.add_button :

Adds a button with the given text and sets things up so that clicking the button will emit the Gtk.Dialog ::response signal with the given response_id. The button is appended to the end of the dialog’s action area. The button widget is returned, but usually you don’t need it.

如果你想添加几个按钮,那么你可以使用Gtk.Dialog.add_buttons :

The add_buttons() method adds several buttons to the Gtk.Dialog using the button data passed as arguments to the method. This method is the same as calling the Gtk.Dialog.add_button() repeatedly.

The button data pairs - button text (or stock ID) and a response ID integer are passed individually. For example:

dialog.add_buttons(Gtk.STOCK_OPEN, 42, "Close", Gtk.ResponseType.CLOSE) 

will add “Open” and “Close” buttons to dialog.