【发布时间】:2012-11-14 04:10:47
【问题描述】:
最简单的例子。我们通过 Gtk 创建一个窗口,我们在其中添加 Gtk.DrawingArea 的绘图区域,并在其上通过 Cairo 绘制文本。
例子:
#!/usr/bin/env python
from gi.repository import Gtk
import cairo
class MyWindow (Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='MyWindow')
darea = Gtk.DrawingArea()
darea.connect('draw', self.on_draw)
self.add(darea)
def on_draw(self, widget, ctx):
ctx.set_source_rgb(0, 0, 0)
ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_NORMAL)
ctx.set_font_size(20)
ctx.move_to(10, 20)
ctx.show_text("Text...")
win = MyWindow()
win.connect('delete-event', Gtk.main_quit)
win.show_all()
Gtk.main()
在我看来,Python 2.7 上的一切都可以完美运行,但只需将 Python 更改为 Python3,并且不再绘制文本。 可能有什么问题?
【问题讨论】:
-
适用于我在 Ubuntu 12.10 上使用 Python 3.2.3。您使用的是哪个发行版?
-
我使用的是 Ubuntu 12.04。在 ubuntu 12.10 中我知道多少默认使用 python 3?并且在 Ubuntu 12.04 中使用了 python 2.7。对我来说,任何已建立的软件包都不够吗?
标签: python-3.x cairo