我最近了解了Python框架kivy并开始遵循the simple paint app tutorial。现在我想保存绘制为.png文件的内容,而不是彩色点,它只导出黑色背景。Export_to_png只保存背景
这是我的代码示例:
import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Ellipse, Line
class MyPaintWidget(Widget):
def on_touch_down(self,touch):
color=(0,0,1)
with self.canvas:
Color(*color)
d=30.
Ellipse(pos=(touch.x-d/2., touch.y-d/2.), size=(d,d))
class MyPaintApp(App):
def build(self):
parent=Widget()
self.painter=MyPaintWidget()
ssbtn=Button(text='Save')
ssbtn.bind(on_release=self.save_screenshot)
parent.add_widget(self.painter)
parent.add_widget(ssbtn)
return parent
def save_screenshot(self,obj):
self.painter.export_to_png("screenshot.png")
if __name__ == '__main__':
MyPaintApp().run()
我在做什么错?谢谢你的帮助。
弄清楚什么是错的最好方法是使用:https://kivy.org/docs/api-kivy.modules.inspector.html#module-kivy.modules.inspector,你可以激活它正如它在此处所述:https://kivy.org/docs/api-kivy.modules.html#activating-a-module,通过在'[modules]'下的'config.ini'文件中添加'inspector ='。 – fins