Я новичок как в python, так и в киви. Я создавал приложение, используя kivy для gui, где пользователь может вставлять различные входные данные в сетку, выполненную с большим количеством текстового ввода. После этого я сохраняю и манипулирую этими данными, чтобы отобразить их на новом экране, называемом «вывод», после нажатия кнопки. Вот где у меня проблемы: мне нужно построить последний «выходной» экран с 1 большой диаграммой паука вверху и 4 маленькими диаграммами внизу (4 строки + 1 строка для будущей кнопки «сохранить как ...») ), но я не могу понять, как вставить свои графики в экран «вывода» моего приложения KIVY после нажатия кнопки на предыдущем экране. Я видел несколько примеров использования kivy.garden, но я все равно не смог найти решение.
вот код python:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image, AsyncImage
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.screenmanager import ScreenManager
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import FadeTransition
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
import matplotlib.pyplot as plt
import kivy_garden.graph
##matplotlib.use('module://kivy.garden.matplotlib.backend_kivy')
from kivy.properties import ObjectProperty
import numpy as np
class Output(Screen):
##Plot with random numbers, i must change those data with the user's data collected and manipulated in the previous screen
Cooperazione = 70
Disorganizzazione = 30
Conflittualità = 14
values = [Cooperazione, Disorganizzazione, Conflittualità]
labels = ["Cooperazione", "Disorganizzazione", "Conflittualità"]
num_labels = np.array(len(labels))
angles = np.linspace(0, 2 * np.pi, num_labels, endpoint=False).tolist()
values += values[:1]
angles += angles[:1]
fig, ax = plt.subplots(figsize=(8, 6), subplot_kw=dict(polar=True))
ax.plot(angles, values, color='red', linewidth=1)
ax.fill(angles, values, color='red', alpha=0.25)
ax.set_theta_offset(np.pi / 2)
ax.set_theta_direction(-1)
ax.set_thetagrids(np.degrees(angles), labels)
ax.set_rlabel_position(180 / num_labels)
ax.set_ylim(0, 100)
ax.set_rgrids([0, 20, 40, 60, 80, 100])
for label, angle in zip(ax.get_xticklabels(), angles): ##Va a spostare, non so come, le etichette fuori dal cerchio
if angle in (0, np.pi):
label.set_horizontalalignment('center')
elif 0 < angle < np.pi:
label.set_horizontalalignment('left')
else:
label.set_horizontalalignment('right')
ax.set_title('Indici Generali', y=1.08)
plt.show()
pass
class MyLayout(Screen):
pass
class LtpLayout(Screen):
def SaveData(self):
items = []
shape = [15,4]
for k,v in self.ids.items():
items.append(v.text)
items = np.array(items).reshape(shape)
##Scale con elementi singoli
PS = items[0]
IP = items[1]
IR = items[2]
ST = items[3]
Cocos = items[4]
Inq = items[5]
Cal = items[6]
Val = items[7]
Aute = items[8]
Eac = items[9]
Ecc = items[10]
Sos = items[11]
Conf = items[12]
Coin = items[13]
Auto = items[14]
##Scale con tot elementi interni
PS_tot = np.sum(PS)
IP_tot = np.sum(IP)
IR_tot = np.sum(IR)
ST_tot = np.sum(ST)
Cocos_tot = np.sum(Cocos)
Inq_tot = np.sum(Inq)
Cal_tot = np.sum(Cal)
Val_tot = np.sum(Val)
Aute_tot = np.sum(Aute)
Eac_tot = np.sum(Eac)
Ecc_tot = np.sum(Ecc)
Sos_tot = np.sum(Sos)
Conf_tot = np.sum(Conf)
Coin_tot = np.sum(Coin)
Auto_tot = np.sum(Auto)
##I 3 indici totali
IND_Coop_tot = np.sum(PS_tot,IP_tot,Cocos_tot,Inq_tot,Cal_tot,Eac_tot,Sos_tot,Auto_tot)
IND_Conflitt_tot = np.sum(PS_tot,8-IR_tot,8-Cocos_tot,8-Aute_tot,8-Conf_tot,8-Cal_tot,8-Ecc_tot,8-Sos_tot)
IND_Disorg_tot = np.sum(8-IP_tot,8-PS_tot,8-IR_tot,8-Cocos_tot,8-ST_tot,8-Auto_tot,8-Inq_tot,8-Val_tot)
##I 3 indici, fase x fase
IND_Coop_1 = np.sum(PS[0],IP[0],Cocos[0],Inq[0],Cal[0],Eac[0],Sos[0],Auto[0])
IND_Coop_2 = np.sum(PS[1],IP[1],Cocos[1],Inq[1],Cal[1],Eac[1],Sos[1],Auto[1])
IND_Coop_2 = np.sum(PS[2],IP[2],Cocos[2],Inq[2],Cal[2],Eac[2],Sos[2],Auto[2])
IND_Coop_4 = np.sum(PS[3],IP[3],Cocos[3],Inq[3],Cal[3],Eac[3],Sos[3],Auto[3])
IND_Conflitt_1 = np.sum(PS[0],2-IR[0],2-Cocos[0],2-Aute[0],2-Conf[0],2-Cal[0],2-Ecc[0],2-Sos[0])
IND_Conflitt_2 = np.sum(PS[1],2-IR[1],2-Cocos[1],2-Aute[1],2-Conf[1],2-Cal[1],2-Ecc[1],2-Sos[1])
IND_Conflitt_3 = np.sum(PS[2],2-IR[2],2-Cocos[2],2-Aute[2],2-Conf[2],2-Cal[2],2-Ecc[2],2-Sos[2])
IND_Conflitt_4 = np.sum(PS[3],2-IR[3],2-Cocos[3],2-Aute[3],2-Conf[3],2-Cal[3],2-Ecc[3],2-Sos[3])
IND_Disorg_1 = np.sum(2-IP[0],2-PS[0],2-IR[0],2-Cocos[0],2-ST[0],2-Aut[0],2-Inq[0],2-Val[0])
IND_Disorg_2 = np.sum(2-IP[1],2-PS[1],2-IR[1],2-Cocos[1],2-ST[1],2-Aut[1],2-Inq[1],2-Val[1])
IND_Disorg_3 = np.sum(2-IP[2],2-PS[2],2-IR[2],2-Cocos[2],2-ST[2],2-Aut[2],2-Inq[2],2-Val[2])
IND_Disorg_4 = np.sum(2-IP[3],2-PS[3],2-IR[3],2-Cocos[3],2-ST[3],2-Aut[3],2-Inq[3],2-Val[3])
pass
class ControlloSchermi (ScreenManager):
pass
def build(self):
sm = ControlloSchermi()
class IntroApp(App):
def build(self):
return ControlloSchermi()
IntroApp().run()
и вот файл kivy:
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
<ControlloSchermi>
MyLayout:
LtpLayout:
Output:
<MyLayout>
name: "main"
BoxLayout:
orientation: 'vertical'
size: self.size
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: "digital brain.jpg"
Label:
text: "Digital Psychometrics"
font_size: 40
bold: True
Button:
on_release: app.root.current = "LTP"
font_size: 15
text: "ACCEDI"
bolf: True
pos_hint_y: 0.5
pos_hint: {'center_x': 0.5, 'center_y': .5}
size: 200, 50
size_hint_x: None
size_hint_y: None
background_normal: ''
background_color: (0, 1, 1, 1)
Label:
text: ''
pos_hint_y: 0.5
pos_hint: {'center_x': 0.5, 'center_y': .5}
size: 200, 50
size_hint_x: None
size_hint_y: None
<LtpLayout>
name: "LTP"
on_enter: PS1.focus = True
BoxLayout:
orientation: "vertical"
canvas.before:
Color:
rgba: 0.03,0.1,0.16,1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size_hint_y: 0.1
orientation: "horizontal"
Label:
canvas.before:
Color:
rgba: 0.12, 0.47, 0.49,1
Rectangle:
pos: self.pos
size: self.size
text: "Tabella per l'inserimento degli input"
bold: True
font_size: 25
GridLayout:
padding: 40,10
cols: 5
size_hint_y: 0.8
Label:
text: "SCALE"
bold: True
font_size: 20
Label:
text: "Fase 1"
bold: True
Label:
text: "Fase 2"
bold: True
Label:
text: "Fase 3"
bold: True
Label:
text: "Fase 4"
bold: True
Label:
text: "Posture e sguardi"
size_hint_x: 2.2
TextInput:
id: PS1
hint_text: "Input"
multiline: False
on_text_validate: PS2.focus = True
TextInput:
id: PS2
multiline: False
hint_text: "Input"
on_text_validate: PS3.focus = True
TextInput:
id: PS3
multiline: False
hint_text: "Input"
on_text_validate: PS4.focus = True
TextInput:
id: PS4
multiline: False
hint_text: "Input"
on_text_validate: IP1.focus = True
Label:
text: "Inclusione partners"
TextInput:
id: IP1
hint_text: "Input"
multiline: False
on_text_validate: IP2.focus = True
TextInput:
id: IP2
multiline: False
hint_text: "Input"
on_text_validate: IP3.focus = True
TextInput:
id: IP3
multiline: False
hint_text: "Input"
on_text_validate: IP4.focus = True
TextInput:
id: IP4
multiline: False
hint_text: "Input"
on_text_validate: IR1.focus = True
Label:
text: "Implicazione ruoli"
TextInput:
id: IR1
hint_text: "Input"
multiline: False
on_text_validate: IR2.focus = True
TextInput:
id: IR2
multiline: False
hint_text: "Input"
on_text_validate: IR3.focus = True
TextInput:
id: IR3
multiline: False
hint_text: "Input"
on_text_validate: IR4.focus = True
TextInput:
id: IR4
multiline: False
hint_text: "Input"
on_text_validate: ST1.focus = True
Label:
text: "Struttura e tempo"
TextInput:
id: ST1
hint_text: "Input"
multiline: False
on_text_validate: ST2.focus = True
TextInput:
id: ST2
multiline: False
hint_text: "Input"
on_text_validate: ST3.focus = True
TextInput:
id: ST3
multiline: False
hint_text: "Input"
on_text_validate: ST4.focus = True
TextInput:
id: ST4
multiline: False
hint_text: "Input"
on_text_validate: Cocos1.focus = True
Label:
text: "Co-costruzione"
TextInput:
id: Cocos1
hint_text: "Input"
multiline: False
on_text_validate: Cocos2.focus = True
TextInput:
id: Cocos2
multiline: False
hint_text: "Input"
on_text_validate: Cocos3.focus = True
TextInput:
id: Cocos3
multiline: False
hint_text: "Input"
on_text_validate: Cocos4.focus = True
TextInput:
id: Cocos4
multiline: False
hint_text: "Input"
on_text_validate: Inq1.focus = True
Label:
text: "Inquadramento"
TextInput:
id: Inq1
hint_text: "Input"
multiline: False
on_text_validate: Inq2.focus = True
TextInput:
id: Inq2
multiline: False
hint_text: "Input"
on_text_validate: Inq3.focus = True
TextInput:
id: Inq3
multiline: False
hint_text: "Input"
on_text_validate: Inq4.focus = True
TextInput:
id: Inq4
multiline: False
hint_text: "Input"
on_text_validate: Cal1.focus = True
Label:
text: "Calore famigliare"
TextInput:
id: Cal1
hint_text: "Input"
multiline: False
on_text_validate: Cal2.focus = True
TextInput:
id: Cal2
multiline: False
hint_text: "Input"
on_text_validate: Cal3.focus = True
TextInput:
id: Cal3
multiline: False
hint_text: "Input"
on_text_validate: Cal4.focus = True
TextInput:
id: Cal4
multiline: False
hint_text: "Input"
on_text_validate: Val1.focus = True
Label:
text: "Validazione"
TextInput:
id: Val1
hint_text: "Input"
multiline: False
on_text_validate: Val2.focus = True
TextInput:
id: Val2
multiline: False
hint_text: "Input"
on_text_validate: Val3.focus = True
TextInput:
id: Val3
multiline: False
hint_text: "Input"
on_text_validate: Val4.focus = True
TextInput:
id: Val4
multiline: False
hint_text: "Input"
on_text_validate: Aute1.focus = True
Label:
text: "Autenticita"
TextInput:
id: Aute1
hint_text: "Input"
multiline: False
on_text_validate: Aute2.focus = True
TextInput:
id: Aute2
multiline: False
hint_text: "Input"
on_text_validate: Aute3.focus = True
TextInput:
id: Aute3
multiline: False
hint_text: "Input"
on_text_validate: Aute4.focus = True
TextInput:
id: Aute4
multiline: False
hint_text: "Input"
on_text_validate: Eac1.focus = True
Label:
text: "Ris. errori att. condivise"
TextInput:
id: Eac1
hint_text: "Input"
multiline: False
on_text_validate: Eac2.focus = True
TextInput:
id: Eac2
multiline: False
hint_text: "Input"
on_text_validate: Eac3.focus = True
TextInput:
id: Eac3
multiline: False
hint_text: "Input"
on_text_validate: Eac4.focus = True
TextInput:
id: Eac4
multiline: False
hint_text: "Input"
on_text_validate: Ecc1.focus = True
Label:
text: "Ris. errori camb. contesto"
TextInput:
id: Ecc1
hint_text: "Input"
multiline: False
on_text_validate: Ecc2.focus = True
TextInput:
id: Ecc2
multiline: False
hint_text: "Input"
on_text_validate: Ecc3.focus = True
TextInput:
id: Ecc3
multiline: False
hint_text: "Input"
on_text_validate: Ecc4.focus = True
TextInput:
id: Ecc4
multiline: False
hint_text: "Input"
on_text_validate: Sos1.focus = True
Label:
text: "Sostegno"
TextInput:
id: Sos1
hint_text: "Input"
multiline: False
on_text_validate: Sos2.focus = True
TextInput:
id: Sos2
multiline: False
hint_text: "Input"
on_text_validate: Sos3.focus = True
TextInput:
id: Sos3
multiline: False
hint_text: "Input"
on_text_validate: Sos4.focus = True
TextInput:
id: Sos4
multiline: False
hint_text: "Input"
on_text_validate: Conf1.focus = True
Label:
text: "Conflitto"
TextInput:
id: Conf1
hint_text: "Input"
multiline: False
on_text_validate: Conf2.focus = True
TextInput:
id: Conf2
multiline: False
hint_text: "Input"
on_text_validate: Conf3.focus = True
TextInput:
id: Conf3
multiline: False
hint_text: "Input"
on_text_validate: Conf4.focus = True
TextInput:
id: Conf4
multiline: False
hint_text: "Input"
on_text_validate: Coin1.focus = True
Label:
text: "Coinvolgimento"
TextInput:
id: Coin1
hint_text: "Input"
multiline: False
on_text_validate: Coin2.focus = True
TextInput:
id: Coin2
multiline: False
hint_text: "Input"
on_text_validate: Coin3.focus = True
TextInput:
id: Coin3
multiline: False
hint_text: "Input"
on_text_validate: Coin4.focus = True
TextInput:
id: Coin4
multiline: False
hint_text: "Input"
on_text_validate: Auto1.focus = True
Label:
text: "Autor./limiti/autonomia"
TextInput:
id: Auto1
hint_text: "Input"
multiline: False
on_text_validate: Auto2.focus = True
TextInput:
id: Auto2
multiline: False
hint_text: "Input"
on_text_validate: Auto3.focus = True
TextInput:
id: Auto3
multiline: False
hint_text: "Input"
on_text_validate: Auto4.focus = True
TextInput:
id: Auto4
multiline: False
hint_text: "Input"
## Focus sul pulsante di avvio on_text_validate: PS2.focus = True
BoxLayout:
padding: 10,10
orientation: "horizontal"
size_hint_y: 0.1
Label:
text: ""
size_hint_x: 0.69
Button:
on_release: root.SaveData()
on_release: app.root.current = "Output"
text: "Conferma"
size_hint_x: 0.2
Label:
text: ''
size_hint_x:0.01
Button:
text: "Annulla"
size_hint_x: 0.1
##on_release: on_release: root.clear_inputs()
<Output>:
name: "Output"
BoxLayout:
Label:
text: "Output"
Кто-то может объяснить мне, как использовать, простыми словами, kivy.garden или подсказать, как отобразить эти графики на экране вывода?