class PieChart(Widget):
def pie():
drawPie()<PieChart>:
canvas:
Color:
rgb: 1, 1, .5
Rectangle:
pos: self.pos
size: self.size
...... root.pie() # here is the problem, I can't get to do the right coding
<WidgetLayout>:
orientation: 'vertical'
chart: pie_chart
canvas:
Rectangle:
pos: 0,0
size: self.width, 10
PieChart:
id: pie_chart
GridLayout:
cols: 2
Button:
text: 'A'
font_size: 50
on_press: root.callback(self.text)
Button:
text: 'B'
font_size: 50
on_press: root.callback(self.text)
Button:
text: 'C'
font_size: 50
on_press: root.callback(self.text)
Button:
text: 'D'
font_size: 50
on_press: root.callback(self.text)
on_press: pie_chart.pie()from kivy.app import Appfrom kivy.uix.scatter import Scatter
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widgetimport requests
list = [0, 0, 0, 0]
class CombWidget(Widget):
chart = ObjectProperty(None)
def callback(self, value):
print ('The %s button has been pressed' % value)
counter(value)
class PieChart(Widget):
def on_touch_down(self, touch):
drawPie()
class TestApp(App):
def build(self):
return CombWidget()
def counter(x):
global list if x == 'A':
list[0] = list[0] + 1
elif x == 'B':
list[1] = list[1] + 1
elif x == 'C':
list[2] = list[2] + 1
elif x == 'D':
list[3] = list[3] + 1
def drawPie():
from pylab import * # make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8]) # The slices will be ordered and plotted counter-clockwise.
labels = 'A', 'B', 'C', 'D'
fracs = [15, 30, 45, 10]
explode=(0, 0.05, 0, 0) pie(fracs, explode=explode, labels=labels,
autopct='%1.1f%%', shadow=True, startangle=90)
# The default startangle is 0, which would start
# the Frogs slice on the x-axis. With startangle=90,
# everything is rotated counter-clockwise by 90 degrees,
# so the plotting starts on the positive y-axis. title('Button clicks', bbox={'facecolor':'0.8', 'pad':5}) show()
if __name__ == "__main__":
TestApp().run()
<CombWidget>:
BoxLayout:
orientation: 'vertical'
size: root.size PieChart:
size_hint: 1, 0.8 GridLayout:
cols: 2
size_hint: 1, 0.2
row_force_default: True
row_default_height: 50
spacing: 10
padding_bottom: 10 Button:
text: 'A'
font_size: 50
on_press: root.callback(self.text)
Button:
text: 'B'
font_size: 50
on_press: root.callback(self.text)
Button:
text: 'C'
font_size: 50
on_press: root.callback(self.text)
Button:
text: 'D'
font_size: 50
on_press: root.callback(self.text)
from kivy.clock import Clock
class CombWidget(Widget):
chart = ObjectProperty(None)
def __init__(self, **kwargs):
super(CombWidget, self).__init__(**kwargs)
Clock.schedule_once(lambda dt: drawPie())