早上好,
我正在尝试将 a 添加Gtk.Entry
到Gtk.MessageDialog
. 使用以下代码,我似乎添加了,Gtk.Entry
但它在对话框窗口(Python3/Gtk3)上不可见:
#!/usr/bin/python3
from gi.repository import Gtk
def get_user_pw(parent, message, default=''):
dialogWindow = Gtk.MessageDialog(parent,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.QUESTION,
Gtk.ButtonsType.OK_CANCEL,
message)
dialogBox = dialogWindow.get_content_area()
userEntry = Gtk.Entry()
userEntry.set_visibility(False)
userEntry.set_invisible_char("*")
userEntry.set_size_request(250,0)
userEntry.set_text("Test")
dialogBox.pack_end(userEntry, False, False, 0)
#dialogWindow.vbox.pack_start(userEntry, False, False, 0)
response = dialogWindow.run()
text = userEntry.get_text()
dialogWindow.destroy()
if response == Gtk.ResponseType.OK:
return text
else:
return None
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="MyWindowTitle")
userPassphrase = get_user_pw(self, "SSH key passphrase")
print("User passphrase: " + userPassphrase)
此代码打印:
User passphrase: Test
我正在寻找有关使条目可见和可编辑的线索,欢迎提供任何帮助。
参考: http:
//python-gtk-3-tutorial.readthedocs.org/en/latest/dialogs.html
http://developer.gnome.org/gtk3/3.2/GtkDialog.html
简单、通用和可重复使用的入口PyGTK 中的对话框(有时称为输入对话框)