我有一个登录对话框,工作正常,但作为response_ok,它只接受ok按钮(尽管作为CANCEL,我可以从键盘按esc)。我试着让它在回车键上做出反应,我觉得应该很容易,但对我来说不是。我试过用set_default_response和其他一些响应,但是没有用。我希望有比连接信号更简单的方法。代码如下:
def get_user_pw(self):
dialogWindow = Gtk.MessageDialog(self,Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,Gtk.MessageType.QUESTION,Gtk.ButtonsType.OK_CANCEL,"Log in")
dialogBox = dialogWindow.get_content_area()
login = Gtk.Entry()
pas = Gtk.Entry()
pas.set_visibility(False)
pas.set_invisible_char("*")
dialogBox.pack_end(has, False, False, 0)
dialogBox.pack_end(uzytkownik, False, False, 0)
dialogWindow.show_all()
Gtk.Dialog.set_default_response(dialogWindow,response_id=Gtk.ResponseType.OK)
response = dialogWindow.run()
{some action here}
dialogWindow.destroy()
几天前我也遇到过同样的问题,结果发现解决方案是在
Entry
的activate
信号上使用侦听器。在所以我编辑了您的代码,在username字段中点击Enter将焦点转移到密码字段,在密码字段中,点击Enter模拟单击OK。在
相关问题 更多 >
编程相关推荐