codice:
import pygtk
pygtk.require('2.0')
import gtk
class Interface:
def enter_callback(self, widget, entry):
entry_text = entry.get_text()
print "Entry contents: %s\n" % entry_text
def get_main_menu(self, window):
accel_group = gtk.AccelGroup()
item_factory = gtk.ItemFactory(gtk.MenuBar, "<main>", accel_group)
# This method generates the menu items. Pass to the item factory
# the list of menu items
item_factory.create_items(self.menu_items)
# Attach the new accelerator group to the window.
window.add_accel_group(accel_group)
# need to keep a reference to item_factory to prevent its destruction
self.item_factory = item_factory
# Finally, return the actual menu bar created by the item factory.
return item_factory.get_widget("<main>")
def __init__(self):
self.menu_items = (
( "/_File", None, None, 0, "<Branch>" ),
( "/File/_New", "<control>N", 0, 0, None ),
( "/File/_Open", "<control>O", 0, 0, None ),
( "/File/_Save", "<control>S", 0, 0, None ),
( "/File/Save _As", None, None, 0, None ),
( "/File/sep1", None, None, 0, "<Separator>" ),
( "/File/Quit", "<control>Q", gtk.main_quit, 0, None ),
( "/_Options", None, None, 0, "<Branch>" ),
( "/Options/Test", None, None, 0, None ),
( "/_Help", None, None, 0, "<LastBranch>" ),
( "/_Help/About", None, None, 0, None ),
)
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", lambda w,e: gtk.main_quit())
window.set_title("Sentiment Analysis")
window.set_size_request(800, 600)
main_vbox = gtk.VBox(False, 1)
main_vbox.set_border_width(1)
window.add(main_vbox)
main_vbox.show()
menubar = self.get_main_menu(window)
main_vbox.pack_start(menubar, False, True, 0)
menubar.show()
vbox = gtk.VBox(False, 0)
window.add(vbox)
vbox.show()
entry = gtk.Entry()
entry.set_max_length(50)
entry.connect("activate", self.enter_callback, entry)
entry.set_text("hello")
entry.insert_text(" world", len(entry.get_text()))
entry.select_region(0, len(entry.get_text()))
vbox.pack_start(entry, True, True, 0)
entry.show()
hbox = gtk.HBox(False, 0)
vbox.add(hbox)
hbox.show()
window.show()
def main():
gtk.main()
return 0
if __name__ == "__main__":
Interface()
main()