Holas
para la 1 con gtk.Entry() la tienes
aqui un codigo de un navegador muuuuy sencillo que encontre por ahi
Código Python:
Ver originalimport sys
import gtk
import webkit
DEFAULT_URL = 'http://www.google.com'
class SimpleBrowser:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.window.connect('delete_event', self.close_application)
self.window.set_default_size(800, 600)
vbox = gtk.VBox(spacing=5)
vbox.set_border_width(5)
self.txt_url = gtk.Entry()
self.txt_url.connect('activate', self._txt_url_activate)
self.scrolled_window = gtk.ScrolledWindow()
self.webview = webkit.WebView()
self.scrolled_window.add(self.webview)
vbox.pack_start(self.txt_url, fill=False, expand=False)
vbox.pack_start(self.scrolled_window, fill=True, expand=True)
self.window.add(vbox)
def _txt_url_activate(self, entry):
self._load(entry.get_text())
def _load(self, url):
self.webview.open(url)
def open(self, url):
self.txt_url.set_text(url)
self.window.set_title('SimpleBrowser - %s' % url)
self._load(url)
def show(self):
self.window.show_all()
def close_application(self, widget, event, data=None):
gtk.main_quit()
if __name__ == '__main__':
if len(sys.argv) > 1:
url = sys.argv[1]
else:
url = DEFAULT_URL
# PyWebkitGTK necesita habilitar el soporte de los hilos en PyGTK
gtk.gdk.threads_init()
browser = SimpleBrowser()
browser.open(url)
browser.show()
gtk.main()
y para el 2, de gtk no se casi nada pero encontre este codigo que te serviria
Código Python:
Ver original#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import os
import sys
#gtk
import pygtk
if sys.platform != 'win32':
pygtk.require('2.0')
import gtk
import gobject
class WinTest:
"""Main Window"""
def __init__(self):
"""test"""
#build the window
self.winMain = gtk.Window()
#set window properties
self.winMain.set_events(
gtk.gdk.KEY_PRESS_MASK |
gtk.gdk.KEY_RELEASE_MASK)
print "events=",self.winMain.get_events()
self.winMain.connect('key-press-event', self.on_winMain_key_press)
self.winMain.connect('key-release-event', self.on_winMain_key_press)
self.winMain.connect('delete-event', self.on_winMain_delete_event)
self.winMain.set_size_request(300, 400)
self.winMain.show()
def on_winMain_key_press(self, widget, event, *args):
"""handle keyboard events"""
keyname = gtk.gdk.keyval_name(event.keyval).upper()
if event.type == gtk.gdk.KEY_PRESS:
if keyname == 'ESCAPE':
self.on_winMain_delete_event()
else:
print "key press=", keyname
elif event.type == gtk.gdk.KEY_RELEASE:
print "key release=", keyname
return False
def on_winMain_delete_event(self, *args):
"""done, quit the application"""
#exit gtk loop
gtk.main_quit()
return False
if __name__ == '__main__':
#instantiate main GUI window class
app = WinTest()
#and... go...
gtk.main()
Saludos