はあなたとGooCanvasに切り替えて少しあなたの人生を簡素化することができます。間違いなく、カイロと下位レベルのツールを使用する方が効率的で高速ですが、ウィジェット(ボタンなど)を描画するのに適しています。再描画イベントの世話をすることで、あなたの人生を容易にすることができますとGooCanvasのようなキャンバスを使用し、それはあなたが物事を行うことができますちょうど空のウィジェットです
、および -
描画領域は、描画ツールが本当にいないことに注意してください。など、レイヤー、マウスイベント、印刷に描くよう、あなたに有益なものを与えて
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# test_goo.py
#
# Copyright 2016 John Coppens <[email protected]>
#
# 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.
#
#
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())
canvas = GooCanvas.Canvas()
root_layer = canvas.get_root_item()
# Draw a rectangle:
rect = GooCanvas.CanvasRect(
parent = root_layer,
x = 20, y = 50,
width = 60, height = 75,
line_width = 2.0,
stroke_color = "Yellow")
# Draw some text:
text1 = GooCanvas.CanvasText(
parent = root_layer,
x = 50, y = 70,
font = "Times 25",
text = "Hi there",
fill_color = "red")
self.add(canvas)
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))
人々は頻繁に彼らが本当に分からないものの悪口を言います。多くの場合、私は生産性のためにPythonを好んでいます.Cで書かれた同じプログラムは、書き込みとデバッグに2倍以上の時間を要します。速度が問題ではない場合(現代のマシンではほとんどありません)、Pythonは素晴らしいです。ここで
は、いくつかの参照は、以下のとおりです。