Good afternoon, I want to make a program that uses several combobox and in a single window. But I can not get both of them to appear. When I run the program, only one of the combobox appears. Below I send the current code.
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.textinput import TextInput
from kivy.properties import StringProperty, ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.dropdown import DropDown
from kivy.properties import ListProperty
from kivy.core.window import Window
class ComboPotenciaConsumo(BoxLayout):
textoEntradaPotenciaConsumo = StringProperty()
opcoesPotenciaConsumo = ListProperty()
valorInicialPotenciaConsumo = StringProperty()
def __init__(self, **kwargs):
super(ComboPotenciaConsumo, self).__init__(**kwargs)
self.opcoesPotenciaConsumo = ['Potência', 'Consumo']
self.valorInicialPotenciaConsumo = 'Potência'
def print_txt1(self):
if self.textoEntradaPotenciaConsumo == 'Potência':
a = 1
elif self.textoEntradaPotenciaConsumo == 'Consumo':
a = 2
print('{}'.format(a))
class ComboPotenciaPainel(BoxLayout):
textoEntradaPotenciaPainel = StringProperty()
opcoesPotenciaPainel = ListProperty()
valorInicialPotenciaPainel = StringProperty()
def __init__(self, **kwargs):
super(ComboPotenciaPainel, self).__init__(**kwargs)
self.opcoesPotenciaPainel =['275 Wp', '330 Wp', '360 Wp']
def print_txt2(self):
if self.textoEntradaPotenciaPainel == '275 Wp':
potenciaPainel = 275
elif self.textoEntradaPotenciaPainel == '330 Wp':
potenciaPainel = 330
elif self.textoEntradaPotenciaPainel == '360 Wp':
potenciaPainel = 360
print('{}'.format(potenciaPainel))
class ProgramaOrcamentoKivy(App):
def build(self):
return ComboPotenciaConsumo()
return ComboPotenciaPainel()
if __name__ == '__main__':
Window.size = (1000, 300)
ProgramaOrcamentoKivy().run()
Below I also send the kv file
<ComboPotenciaConsumo>:
opcoesPotenciaConsumo: spinner_1.values
valorInicialPotenciaConsumo: spinner_1.text
orientation: 'vertical'
Label:
text: 'Orcamentos 1.1'
font_size: '40sp'
bold: True
color: [1, 0, 0, 1]
height: '32dp'
GridLayout:
cols: 2
spacing: 20
padding: [20,20]
Button:
on_press: root.print_txt1()
text: 'Button 1'
id: but_1
size_hint: [1, None]
height: '32dp'
Spinner:
id: spinner_1
values: root.opcoesPotenciaConsumo
size_hint: [0.5, None]
height: '32dp'
on_text: root.textoEntradaPotenciaConsumo = self.text
:
opcoesPotenciaConsumo: spinner_2.values
valorInicialPotenciaConsumo: spinner_2.text
orientation: 'vertical'
Label:
text: 'Orcamentos 1.1'
font_size: '40sp'
bold: True
color: [1, 0, 0, 1]
height: '32dp'
GridLayout:
cols: 2
spacing: 20
padding: [20,20]
Button:
on_press: root.print_txt2()
text: 'Button 2'
id: but_2
height: '32dp'
Spinner:
id: spinner_2
values: root.opcoesPotenciaPainel
size_hint: [8, None]
height: '32dp'
on_text: root.textoEntradaPotenciaPainel = self.text