|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="checkbutton.py" xml:lang="es">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">CheckButton (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#buttons"/>
|
|
Packit |
1470ea |
<link type="next" xref="togglebutton.py"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-09" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Marta Maria Casetti</name>
|
|
Packit |
1470ea |
<email its:translate="no">mmcasetti@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Un botón conmutador en una ventana</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Daniel Mustieles</mal:name>
|
|
Packit |
1470ea |
<mal:email>daniel.mustieles@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011 - 2017</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Nicolás Satragno</mal:name>
|
|
Packit |
1470ea |
<mal:email>nsatragno@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012 - 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Jorge González</mal:name>
|
|
Packit |
1470ea |
<mal:email>jorgegonz@svn.gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>CheckButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/checkbutton.png"/>
|
|
Packit |
1470ea |
Este CheckButton cambia el título.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Código usado para generar este ejemplo</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
# a window
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="CheckButton Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(300, 100)
|
|
Packit |
1470ea |
self.set_border_width(10)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a new checkbutton
|
|
Packit |
1470ea |
button = Gtk.CheckButton()
|
|
Packit |
1470ea |
# with a label
|
|
Packit |
1470ea |
button.set_label("Show Title")
|
|
Packit |
1470ea |
# connect the signal "toggled" emitted by the checkbutton
|
|
Packit |
1470ea |
# with the callback function toggled_cb
|
|
Packit |
1470ea |
button.connect("toggled", self.toggled_cb)
|
|
Packit |
1470ea |
# by default, the checkbutton is active
|
|
Packit |
1470ea |
button.set_active(True)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# add the checkbutton to the window
|
|
Packit |
1470ea |
self.add(button)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function
|
|
Packit |
1470ea |
def toggled_cb(self, button):
|
|
Packit |
1470ea |
# if the togglebutton is active, set the title of the window
|
|
Packit |
1470ea |
# as "Checkbutton Example"
|
|
Packit |
1470ea |
if button.get_active():
|
|
Packit |
1470ea |
self.set_title("CheckButton Example")
|
|
Packit |
1470ea |
# else, set it as "" (empty string)
|
|
Packit |
1470ea |
else:
|
|
Packit |
1470ea |
self.set_title("")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Métodos útiles para un widget «CheckButton»</title>
|
|
Packit |
1470ea |
En la línea 17 la señal «toggled» se conecta a una función de retorno de llamada toggled_cb() usando widget.connect(señal, función de retorno de llamada) . Consulte la <link xref="signals-callbacks.py"/> para obtener una explicación más detallada.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>Referencias de la API</title>
|
|
Packit |
1470ea |
En este ejemplo se usa lo siguiente:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkApplicationWindow.html">GtkApplicationWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkToggleButton.html">GtkToggleButton</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkCheckButton.html">GtkCheckButton</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|