Simple, versatile and re-usable entry dialog (sometimes referred to as input dialog) in PyGTK

前端 未结 3 499
天涯浪人
天涯浪人 2020-12-11 18:57

I am searching for a simple dialog with a text entry widget asking the user for some input. The dialog should be easy to run (like the gtk.MessageDialog variant

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 19:27

    There isn't one available in GTK+. You've got two options:

    • Create a dialog, pack the Entry and any other content you need (probably the best way in my opinion)
    • Retrieve the content_area of the MessageDialog and append an Entry to it.

    Something along the lines of:

    #!/usr/bin/env python
    
    import gtk
    
    messagedialog = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK, message_format="Hello")
    
    action_area = messagedialog.get_content_area()
    
    entry = gtk.Entry()
    action_area.pack_start(entry)
    
    messagedialog.show_all()
    messagedialog.run()
    messagedialog.destroy()
    

    Though it does probably need more refinement to get the Entry to display nicely.

提交回复
热议问题