Home
  Software
    HowTo
      GooCanvas
        Intro

Idioma:
  English

Temas
  Intro
  Ventana
  Canvas
  Caja
  Capa
  Texto
  Caja1
  Reloj
  Reloj1

Introducción a GooCanvas

Demo GooCanvas

Agreamos una capa (transparente) nueva. La capa nueva está desplazada (ver 'x' y 'y')

#!/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)

        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_2.py

6382


(c) John Coppens ON6JC/LW3HAZ correo