Модуль Kivy. Хорошо описано тут -
Вообщем, жалуется на строку 30 (textInput.text = button_text).
Полный текст ошибки: File "F:\python\myCacl.py", line 30, in on_button_press
textInput.text = button_text
NameError: name 'textInput' is not defined
Код:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
buttons = [
["7", "8", "9", "/"],
["4", "5", "6", "*"],
["1", "2", "3", "-"],
[".", "0", "C", "+"],
]
class MainApp(App):
def build(self):
layout = BoxLayout(orientation="vertical")
textInput = TextInput(multiline=False, readonly=False, halign="right", font_size=55)
layout.add_widget(textInput)
textInput.text = "0"
for i in buttons:
help_layout = BoxLayout()
for label in i:
button = Button(text=label,pos_hint={"center_x": 0.5, "center_y": 0.5})
button.bind(on_press=self.on_button_press)
help_layout.add_widget(button)
layout.add_widget(help_layout)
return layout
def on_button_press(self, instance):
button_text = instance.text
textInput.text = button_text
if __name__ == "__main__":
app = MainApp()
app.run()
P.S.Для запуска скрипта нужно установить модуль, забив в cmd pip install kivy