in pygtk how to edit content of an Entry object that added to MenuItem (On Run Time)

265 Views Asked by At

I want to create a MenuItem that an Entry shows on this to user can enter value to the entry widget. This procedure is easy to implement but after showing this Entry it cant get cursor and user cant input text to it, help me to do it please. i used pygtk 2.0 .

#!/usr/bin/env python
import gtk

win = gtk.Window()
win.connect( "destroy", gtk.main_quit )

menubar = gtk.MenuBar()
popup = gtk.Menu()
root_menu = gtk.MenuItem("root")
menu_item = gtk.MenuItem()
field =  gtk.Entry()

win.add( menubar )
menubar.add( root_menu )
root_menu.set_submenu( popup )
popup.append( menu_item )
menu_item.add( field )

win.show_all()    
print field.get_can_focus(), field.get_editable()

gtk.main()
3

There are 3 best solutions below

1
On

Here is a great menubar example -- just copy it and put it menubar_test.py then change the permissions chmod 755 menubar_test.py

Hope this helps you!

0
On

Here is a post announcing that what you are trying to do might be included in GTK 3.4; but I don't know where to find the current state of that code.

1
On

Using pygtk 2.0, I believe you want to use:

field.set_text("Here is my text in gtk.Entry widget")

field.get_text() retrieves the text that you just set above in gtk.Entry.