本文整理汇总了Python中canvas.Canvas.set_style方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.set_style方法的具体用法?Python Canvas.set_style怎么用?Python Canvas.set_style使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.set_style方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSequenceFunctions
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import set_style [as 别名]
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.canvas = Canvas()
self.canvas.code = ""
self.string_rgb = "FFBBAA"
self.rgb = [251,186,10]
def test_out(self):
text = 'ctx = canvas.getContext("2d");'
self.canvas.out(text)
self.assertTrue(self.canvas.code, text)
def test_rgb(self):
r,g,b = self.canvas.rgb(self.string_rgb)
self.assertTrue(r,self.rgb[0])
self.assertTrue(g,self.rgb[1])
self.assertTrue(b,self.rgb[2])
def test_style_for_stroke_width(self):
dictionary = {"stroke-width":"3"}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.lineWidth = 3;")
def test_style_for_stroke_linecap(self):
dictionary = {"stroke-linecap":3}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.lineCap = 3;")
def test_style_for_stroke_linejoin(self):
dictionary = {"stroke-linejoin":3}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.lineJoin = 3;")
def test_style_for_stroke_miterlimit(self):
dictionary = {"stroke-miterlimit":3}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.miterLimit = 3;")
def test_style_for_opacity(self):
dictionary = {"opacity":0.5}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.globalAlpha = 3;")
def test_style_for_stroke(self):
r,g,b = self.rgb
dictionary = {"stroke":self.string_rgb}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.strokeStyle = 'rgb(%d, %d, %d)';" % (r,g,b))
def test_style_for_stroke_with_opacity(self):
r,g,b = self.rgb
dictionary = {"stroke":self.string_rgb, "fill-opacity": 0}
self.canvas.set_style(dictionary)
self.assertTrue(self.canvas.code,"ctx.strokeStyle = 'rgba(%d, %d, %d, %d)';" % (r,g,b,0))