S
S
Stas Povalyaev2022-01-18 15:30:43
Python
Stas Povalyaev, 2022-01-18 15:30:43

How to get updated data from popup in which textinput?

here I made a function that creates a pop-up window in which the form must be filled:
61e6b2532583c300458335.png
but there is a problem, as you can see in the screenshot, textinputs have default values, so when I change it, I think that it will write the values ​​​​from the textinputs to the file, but even when I change the text, it still writes the default value to the file, which is what I specified in the code. Help plz.

my code

def add_label(self, instance):
        # lines.insert(39, 'Text\n')
        #
        #
        #
        layout = BoxLayout(orientation="vertical")
        textinput_name = TextInput(text='name', background_normal='man3.png', font_size='12sp')
        textinput_posX = TextInput(text='pos X', background_normal='man3.png', font_size='12sp')
        textinput_posY = TextInput(text='pos Y', background_normal='man3.png', font_size='12sp')
        object_settings_lbl = Label(text="Object type: Label", font_size='12sp')
        object_name_lbl = Label(text="object name:", font_size='12sp')
        object_pos_lbl = Label(text="position:", font_size='12sp')
        object_size_lbl = Label(text="size:", font_size='12sp')
        object_text_lbl = Label(text="text:", font_size='12sp')
        textinput_width = TextInput(text='width', background_normal='man3.png', font_size='12sp')
        textinput_height = TextInput(text='height', background_normal='man3.png', font_size='12sp')
        textinput_text = TextInput(text='text', background_normal='man3.png', font_size='12sp')
        lbl_font_size = Label(text="font size:", font_size='12sp')
        textinput_font_size = TextInput(text='15sp', background_normal='man3.png', font_size='12sp')
        button = Button(text='Create & close')
        layout.add_widget(object_settings_lbl)
        layout.add_widget(object_name_lbl)
        layout.add_widget(textinput_name)
        layout.add_widget(object_pos_lbl)
        layout.add_widget(textinput_posX)
        layout.add_widget(textinput_posY)
        layout.add_widget(object_size_lbl)
        layout.add_widget(textinput_width)
        layout.add_widget(textinput_height)
        layout.add_widget(object_text_lbl)
        layout.add_widget(textinput_text)
        layout.add_widget(lbl_font_size)
        layout.add_widget(textinput_font_size)
        layout.add_widget(button)
        
        popup = Popup(title='New Label Property', content=layout, size_hint=(None, None), size=(700, 600))
        button.bind(on_press=popup.dismiss)
        popup.open()
        ################################################



        global FILE_NAME
        inp = askopenfile(mode="r", title="add Label")
        if inp is None:
            return
        FILE_NAME = inp.name
        print(FILE_NAME)
        print(inp)


        with open(FILE_NAME, 'rt', encoding='utf-8') as src:
            data = src.read()
        with open(FILE_NAME, 'wt', encoding='utf-8') as dest:
            dest.write(data.replace('# CODE', '# Label\n        '+textinput_name.text+"=Label(text ="+"'"+textinput_text.text+"'"+", font_size="+textinput_font_size.text+", size_hint =("+textinput_width.text+","+textinput_height.text+"), pos_hint = {'center_x': "+textinput_posX.text+", 'center_y':"+textinput_posY.text+"})\n        main_layout.add_widget("+textinput_name.text+")\n# CODE\n"))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question