2011-06-05 11 views
9

O "Cómo agregar un borde visible (delgado) a GtkTextView"? ¿Es alguna vez posible?¿Cómo hacer que GtkTextView se vea como GtkEntry?

Gracias de antemano.

+0

¿Por qué quieres confundir a los usuarios de esa manera? – ptomato

+1

@ptomato Necesito lo mismo. No se trata de confundir al usuario, sino de no confundir al usuario. Quiero un widget de texto de 3 líneas que se comporte exactamente como un widget de Entrada (pero con 3 líneas). La única forma que pude encontrar es modificar un widget TextView ... – xubuntix

Respuesta

0

Utilizando editor de Glade:

  • En el editor claro seleccione su ScrolledWindow (usted ha empacado TextView en ScrolledWindow, ¿no es así :), si no - seleccione su TextView?)
  • Seleccione Widget Porperties ->Común pestaña.
  • Buscar y ajustar Ancho del borde propiedad que usted desea.

De código:

llamada set_border_width(width) método de widget de contenedor (ya sea ScrolledWindow o TextView)

Tenga en cuenta, que en todo caso TextArea no se verá exactamente igual que entrada y depende del tema gtk + utilizado.

0

El uso de gtk.ScrolledWindow.set_shadow_type(type=gtk.SHADOW_ETCHED_IN) mejorará el aspecto pero no coincidirá con el estilo de gtk.Entry.

El borde de la ventana anotada o la vista de texto no es un problema si se coloca en una ventana o panel, pero si el objetivo es crear un formulario con un campo de entrada de varias líneas, se vuelve feo. Aquí es un truco que puede hacer el truco ...

import gtk 

# create an entry widget that we use for appearances only 
e=gtk.Entry() 
e.set_size_request(width=250, height=150) 

# create a texview and accompaying label 
lbl = gtk.Label(str="Comments: ") 
lbl.set_alignment(xalign=1, yalign=0) 
field = gtk.TextView(buffer=None) 
field.set_wrap_mode(wrap_mode=gtk.WRAP_WORD) # or gtk.WRAP_CHAR 

# we need a scroll window 
sw = gtk.ScrolledWindow(hadjustment=None, vadjustment=None) 
sw.set_border_width(border_width=4) 
sw.set_size_request(width=250, height=150) 
sw.set_policy(hscrollbar_policy=gtk.POLICY_NEVER, vscrollbar_policy=gtk.POLICY_AUTOMATIC) 
sw.add(field) 

# create more widgets as needed for form here... 
lbl2 = gtk.Label(str="email: ") 
lbl2.set_alignment(xalign=1, yalign=0) 
field2 = gtk.Entry() 

# put everything in a table so the fields and labels are all aligned 
tbl = gtk.Table(rows=1, columns=2, homogeneous=False) 
tbl.attach(lbl, left_attach=0, right_attach=1, top_attach=0, bottom_attach=1, xoptions=gtk.FILL|gtk.SHRINK, yoptions=gtk.FILL, xpadding=0, ypadding=0) 
# sw and e must be attached in this order, the reverse will not work 
tbl.attach(sw, left_attach=1, right_attach=2, top_attach=0, bottom_attach=1, xoptions=gtk.FILL|gtk.SHRINK, yoptions=gtk.FILL, xpadding=0, ypadding=0) 
tbl.attach(e, left_attach=1, right_attach=2, top_attach=0, bottom_attach=1, xoptions=gtk.FILL|gtk.SHRINK, yoptions=gtk.FILL, xpadding=0, ypadding=0) 
# comment out previous line to see difference 

# attach other widgets here... 
tbl.attach(lbl2, left_attach=0, right_attach=1, top_attach=1, bottom_attach=2, xoptions=gtk.FILL|gtk.SHRINK, yoptions=gtk.FILL, xpadding=0, ypadding=0) 
tbl.attach(field2, left_attach=1, right_attach=2, top_attach=1, bottom_attach=2, xoptions=gtk.FILL|gtk.SHRINK, yoptions=gtk.FILL, xpadding=0, ypadding=0) 

# display it! 
window = gtk.Window() 
window.set_default_size(350, 200) 
window.connect("destroy", lambda w: gtk.main_quit()) 
window.add(tbl) 
window.show_all() 

gtk.main() 

La advertencia es que la barra de desplazamiento (s) se vuelve invisible; se puede seleccionar, y el desplazamiento funciona como siempre. Esto puede ser un problema menor si los datos que se ingresan en el campo tienden a no hacer uso del desplazamiento.

6

Años después ... pero la búsqueda en la web aún no da buenas respuestas a esta pregunta.

La solución es muy sencilla: basta con crear una GtkFrame y añadir la GtkScrolledWindow que contiene el GtkTextView, aquí es un código de ejemplo en Python:

frame = Gtk.Frame() 
scroll = Gtk.ScrolledWindow() 
scroll.set_hexpand(True) 
scroll.set_border_width(3) 
textview = Gtk.TextView() 
scroll.add(textview) 
frame.add(scroll) 
Cuestiones relacionadas