Home
  Software
    HowTo
      GooCanvas
        Intro

Idioma:
  English

Temas
  Intro
  Ventana
  Canvas
  Caja
  Capa
  Texto
  Caja1
  Reloj
  Reloj1

Introducción a GooCanvas

Demo GooCanvas

En la capa nueva, agregamos un texto. Observen que el texto en la capa, está ubicado en el origen, pero toda la capa está desplazada.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#  demo_goocanvas_0.py
#  
#  Copyright 2019 John Coppens <john@jcoppens.com>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  


import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GooCanvas', '2.0')
from gi.repository import Gtk, GooCanvas

class MainWindow(Gtk.Window):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.connect("destroy", lambda x: Gtk.main_quit())
        self.set_size_request(400, 300)

        # Create the GooCanvas widget
        cv = GooCanvas.Canvas()
        # And ask for access to the root layer
        layer0 = cv.get_root_item()

        # Let's draw a rectangle on the root layer
        rect = GooCanvas.CanvasRect(
                    parent = layer0,
                    x = 20, y = 40,
                    width = 80, height = 120,
                    line_width = 1.0,
                    stroke_color = "yellow",
                    fill_color = "green")

        # Create a new layer, offset by x=130, and y=50
        layer1 = GooCanvas.CanvasGroup(
                    parent = layer0,
                    x = 130, y = 50)

        # And draw a text at the new layer's origin
        text = GooCanvas.CanvasText(
                    parent = layer1,
                    x = 0, y = 0,
                    text = "John",
                    font = "Serif 60",
                    fill_color_rgba = 0xff00ffff)

        self.add(cv)
        self.show_all()

    def run(self):
        Gtk.main()


def main(args):
    mainwdw = MainWindow()
    mainwdw.run()

    return 0

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))
Código: demo_goocanvas_3.py

6387


(c) John Coppens ON6JC/LW3HAZ correo