本文整理汇总了Python中canvas.Canvas.set_background方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.set_background方法的具体用法?Python Canvas.set_background怎么用?Python Canvas.set_background使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.set_background方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import set_background [as 别名]
class Window:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete-event", self.delete_event_cb)
self.window.connect("destroy", self.destroy_cb)
self.window.set_border_width(0)
self.window.set_size_request(800, 600)
self.window.show()
self.canvas = Canvas()
self.canvas.set_background((0,0,0))
self.canvas.set_foreground((0,0,0))
self.canvas.set_flags(gtk.HAS_FOCUS|gtk.CAN_FOCUS)
self.canvas.grab_focus()
self.layer1 = CanvasLayer()
self.layer2 = CanvasLayer()
self.canvas.append(self.layer1)
self.canvas.append(self.layer2)
self.canvas.show()
self.window.add(self.canvas)
for n in xrange(100):
o = CanvasRect(self.layer1, 100, 100, 200, 200, filled=True)
o.scale(random(), random(), random(), random())
o.move(randrange(1000), randrange(1000))
o.connect('button-press-event', self.button_press_event_cb)
o.connect('motion-notify-event', self.motion_notify_event_cb)
o.connect('button-release-event', self.button_release_event_cb)
for n in xrange(100):
g = CanvasGroup(self.layer2, fg=(0,0,1))
o = CanvasLine(g, 0, 0, 100, 100)
print(dir(o))
o = CanvasRect(g, 0, 100, 100, 200, filled=True, fg=(0.5, 0.3,0.4),bg=(1, 0.3,0.4))
o = CanvasOval(g, 0, 200, 100, 300, fg=(0.5, 1,0.3))
o = CanvasArc(g, 0, 300, 100, 400, start=0, extent=180)
o = CanvasText(g, 0, 400, text='Hello')
o = CanvasLine(g, 100, 0, 200, 100)
o = CanvasRect(g, 100, 100, 200, 200, filled=True, outline=True)
o = CanvasOval(g, 100, 200, 200, 300, filled=True)
o = CanvasArc(g, 100, 300, 200, 400, start=90, extent=270, filled=True)
o = CanvasText(g, 100, 400, text='World')
g.scale(random(), random(), random(), random())
g.move(randrange(1000), randrange(1000))
g.connect('button-press-event', self.button_press_event_cb)
g.connect('motion-notify-event', self.motion_notify_event_cb)
g.connect('button-release-event', self.button_release_event_cb)
# o = CanvasImage(self.layer1, 0, 0, filename='image2.jpeg')
# o.connect('button-press-event', self.button_press_event_cb)
# o.connect('motion-notify-event', self.motion_notify_event_cb)
# o.connect('button-release-event', self.button_release_event_cb)
# o = CanvasImage(self.layer1, 100, 100, filename='image1.png')
# o.connect('button-press-event', self.button_press_event_cb)
# o.connect('motion-notify-event', self.motion_notify_event_cb)
# o.connect('button-release-event', self.button_release_event_cb)
# o = CanvasFunc(self.layer1, target=self.canvas_func1, args=(), kw={})
self.canvas_button = None
self.item = None
self.item_prev_x = None
self.item_prev_y = None
self.item_button = None
self.window.connect('key-press-event', self.window_key_press_event_cb)
self.window.connect('key-release-event', self.window_key_release_event_cb)
self.canvas.connect('button-press-event', self.canvas_button_press_event_cb)
self.canvas.connect('motion-notify-event', self.canvas_motion_notify_event_cb)
self.canvas.connect('button-release-event', self.canvas_button_release_event_cb)
self.canvas.connect('scroll-event', self.canvas_scroll_event_cb)
def delete_event_cb(self, widget, event, data=None):
return False
def destroy_cb(self, widget, data=None):
gtk.main_quit()
def main(self):
gtk.main()
def button_press_event_cb(self, widget, item, event):
self.item = item
self.item_prev_x = event.x
self.item_prev_y = event.y
self.item_button = event.button
def motion_notify_event_cb(self, widget, item, event):
if self.item_button == 1:
dx = event.x - self.item_prev_x
dy = event.y - self.item_prev_y
self.item.move(dx, dy)
self.item_prev_x = event.x
self.item_prev_y = event.y
def button_release_event_cb(self, widget, item, signal_id):
self.item_button = None
#.........这里部分代码省略.........