@sakair

Как обратится к тексу в codeinput в kivy?

from kivy.app import App

from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.codeinput import CodeInput
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from pygments.lexers import CLexer
from kivy.lang.builder import Builder

Builder.load_file('kv.kv')

usercode = None
codetext = None

class Main(Screen):
    def __init__(self, **kwargs):
        super(Main, self).__init__(**kwargs)
        # #dark okean = 30, 38, 74 | 30/255, 38/255, 74/255
                # #dark kristal = 13, 19, 31 | 13/255, 19/255, 31/255
                # #standart 22, 26, 33 | 22/255, 26/255, 33/255
            #background_color: 22/255, 26/255, 33/255
                # #standart text 182, 189, 204
            #foreground_color: 182/255, 189/255, 204/
        x = CLexer()
        self.codeinput = CodeInput(lexer=x,font_name=('JetMonoBold.ttf'),foreground_color=(182/255, 189/255, 204/255),background_color=(22/255, 26/255, 33/255) ,size_hint=(1,0.9),font_size=(20), text="Hello, I TeaCode")
        self.add_widget(self.codeinput)

class Tea(Screen):
    pass
class Tea_Code(App):
    def build(self):
        return Tea() 
    def coder(self, code):
        global usercode
        usercode = code
        if usercode == "C":
            return print("C")
        elif usercode == "Python":
            return print("Python")
        else:
            return print("Error")
    def screen(self, x):
        self.root.current = x

    def savefile(self):
        global codetext
        codetext = self.root.codeinput.text
        if usercode == "C":
            txt = "tea.c"
        elif usercode == "Python":
            txt = "tea.py"
        else:
            txt = "tea.txt"
        with open(txt, 'w', encoding = 'utf-8') as target:
            target.write(str(codetext))
if __name__ == '__main__':
    Tea_Code().run()

нужно получить текст с codeinput.
  • Вопрос задан
  • 31 просмотр
Пригласить эксперта
Ответы на вопрос 1
milssky
@milssky
Координатор племени фиолетовых обезьянок
Так же, как у обычного TextInput.

It supports all the features provided by the textinput
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы