当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.draw_rect方法代码示例

本文整理汇总了Python中canvas.Canvas.draw_rect方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.draw_rect方法的具体用法?Python Canvas.draw_rect怎么用?Python Canvas.draw_rect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在canvas.Canvas的用法示例。


在下文中一共展示了Canvas.draw_rect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw_rect [as 别名]
 def run(self):
     print 'RUNNING'
     r = lambda: random.randint(0, 255)
     while True:
         Canvas.clear()
         Canvas.draw_rect((0, 0), (200, 200), fill_style='#%02X%02X%02X' % (r(), r(), r()))
         sleep(random.uniform(0.03, 1))
开发者ID:djoeman84,项目名称:tikoApp,代码行数:9,代码来源:app.py

示例2: __init__

# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw_rect [as 别名]

#.........这里部分代码省略.........
			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
	
	def canvas_button_press_event_cb(self, widget, event):
		self.canvas_button = event.button
		if self.canvas_button == 2:
			self.canvas_prev_x = event.x
			self.canvas_prev_y = event.y
	
	def canvas_motion_notify_event_cb(self, widget, event):
		if self.canvas_button == 2:
			dx = event.x - self.canvas_prev_x
			dy = event.y - self.canvas_prev_y
			self.canvas.move_all(dx, dy)
			self.canvas_prev_x = event.x
			self.canvas_prev_y = event.y
		
	def canvas_button_release_event_cb(self, widget, signal_id):
		self.canvas_button = None
	
	def canvas_scroll_event_cb(self, widget, event):
		if event.direction == gtk.gdk.SCROLL_UP:
			self.canvas.scale_all(event.x, event.y, 1.2, 1.2)
		elif event.direction == gtk.gdk.SCROLL_DOWN:
			self.canvas.scale_all(event.x, event.y, 1/1.2, 1/1.2)
	
	def window_key_press_event_cb(self, widget, event):
		print widget, event
	
	def window_key_release_event_cb(self, widget, event):
		print widget, event
	
	def canvas_func1(self, *args, **kw):
		self.canvas.draw_image(0, 0, xs=1.0, ys=1.0, filename='image2.jpeg')
		self.canvas.draw_line(0, 0, 100, 100)
		self.canvas.draw_rect(0, 100, 100, 200)
		self.canvas.draw_oval(0, 200, 100, 300)
		self.canvas.draw_arc(0, 300, 100, 400)
		self.canvas.draw_text(0, 400, "Hello World")
开发者ID:arnew,项目名称:dxf2gcode,代码行数:104,代码来源:example.py


注:本文中的canvas.Canvas.draw_rect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。