0
我有一個繪畫應用程序的這個kivy代碼。在按鈕上繪圖問題
<PaintApp>:
name: "PaintApp"
BoxLayout:
orientation:'vertical'
CanvasWidget:
size_hint_y:.9
BoxLayout:
size_hint:(1,None)
size_hint_y:.1
orientation: 'horizontal'
Button:
text: 'Delete'
font_size: 20
# on_release: root.clear_canvas()
background_normal: 'red_button_normal.png'
background_down: 'red_button_down.png'
border: (2, 2, 2, 2)
right: root.right
top: root.top
width: 80
height: 40
Button:
text: 'Back'
font_size: 20
# on_release: app.root.current= 'ActivitySelectScreen'
background_normal: 'red_button_normal.png'
background_down: 'red_button_down.png'
border: (2, 2, 2, 2)
right: root.right -80
top: root.top
width: 80
height: 40
LineWidthButton:
text: 'Thin'
LineWidthButton:
text: 'Normal'
state: 'down'
LineWidthButton:
text: 'Thick'
ColorButton:
background_color: C('#2980b9')
state: 'down'
ColorButton:
background_color: C('#16a085')
ColorButton:
background_color: C('#27ae60')
ColorButton:
background_color: C('#f39c12')
ColorButton:
background_color: C('#d35400')
ColorButton:
background_color: C('#c0392b')
ColorButton:
background_color: C('#8e44ad')
ColorButton:
background_color: C('#bdc3c7')
ColorButton:
background_color: C('#7f8c8d')
ColorButton:
background_color: C('#2c3e50')
Python代碼:
class CanvasWidget(Widget):
line_width = 2
def on_touch_down(self, touch):
if Widget.on_touch_down(self, touch):
return
with self.canvas:
touch.ud['current_line'] = Line(
points=(touch.x, touch.y),
width=self.line_width)
def on_touch_move(self, touch):
if 'current_line' in touch.ud:
touch.ud['current_line'].points += (touch.x, touch.y)
def set_color(self, new_color):
self.last_color = new_color
self.canvas.add(Color(*new_color))
def set_line_width(self, line_width='Normal'):
self.line_width = {'Thin': 1, 'Normal': 2, 'Thick': 4}[line_width]
def clear_canvas(self):
saved = self.children[:]
self.clear_widgets()
self.canvas.clear()
for widget in saved:
self.add_widget(widget)
輸出的應用程序是這樣的:
它在某種程度上借鑑的按鈕也落後。我不明白爲什麼。當我在框佈局中添加兩個按鈕時。它不會在其他頂部添加一個。