I looked up kivy just today and I was just trying the widgets, everything worked fine until I used the TextInput and when I run it shows a black screen then notify me that python v3.9 stopped responding. When I remove the TextInput widget everything works fine again.
The main.py
from kivy.app import App
from kivy.properties import StringProperty, BooleanProperty
from kivy.uix.gridlayout import GridLayout
class WidgetsButtonClickExample(GridLayout):
my_text = StringProperty("0")
count = 0
is_on = BooleanProperty(False)
def on_button_click(self):
print("Button Clicked")
if self.is_on:
self.count += 1
self.my_text = str(self.count)
def on_toggle_button_state(self, toggle_button):
print("Toggle button state: " + toggle_button.state)
if toggle_button.state == "normal":
toggle_button.text = "OFF"
self.is_on = False
else:
toggle_button.text = "ON"
self.is_on = True
def switch_on_active(self, switch):
print("Switch: " + str(switch.active))
def on_slider_value(self, slider):
print("Slider value: " + str(int(slider.value)))
class TheLabApp(App):
pass
TheLabApp().run()
The .kv file
WidgetsButtonClickExample:
<WidgetsButtonClickExample>
cols: 3
ToggleButton:
text: "OFF"
on_state: root.on_toggle_button_state(self)
size_hint: None, 1
width: "100dp"
Button:
text: "Count"
on_press: root.on_button_click()
disabled: not root.is_on
Label:
text: root.my_text
font_name: "fonts/Lcd.ttf"
font_size: "50dp"
color: 1, .5, 1, .7
Switch:
id: my_switch
size_hint: None, 1
width: "100dp"
on_active: root.switch_on_active(self)
Slider:
disabled: not my_switch.active
id: my_slider
min: 0
max: 100
value: 50 # default value
# on_value: root.on_slider_value(self)
orientation: "horizontal" # v/h
BoxLayout:
orientation: "vertical"
Label:
text: str(int(my_slider.value))
# size_hint: 1, 1
ProgressBar:
max: 100 # min is always 0
value: my_slider.value
TextInput:
If I remove the last line of the .kv file everything works as expected. Can anyone help me with this?