Unable to add an additional username

Viewed 27

I need to create a mini database with Pickle to store the username, I have a text field to input the username, this username defaults are Sarah and Peter.

from kivymd.app import MDApp
from kivy.lang import Builder
import pickle
from kivy.factory import Factory

a = ['Sarah', 'Peter']

class PickleApp(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Teal"

        return Builder.load_file('forth_db.kv')
    
    def add(self):
        global count       
        
        input =  self.root.ids.word_input.text
       
        count = 0
        if count %2 == 0:
            self.a.append(input)
            count = 0
        else:
            self.a.append(input)
        count += 1
        print(a)
        
        self.root.ids.word_input.text = ''
        self.root.ids.word_label.text = f'{self.a}'

I want the username to increase in number such as Sarah, Peter, David, Sally, William and so on. However, when I input David, the label shows Sarah, Peter and David. Later, when I input Lola, it becomes Sarah, Peter and Lola. It simply replaced David with Lola, instead of adding at the end of David.

Following is KV file #:import Factory kivy.factory.Factory MDFloatLayout: BoxLayout: orientation: 'vertical' size: root.width, root.height

    MDLabel:
        id: word_label
        text_size: self.size
        halign: "center"
        valign: "middle"
        text: "Enter A Name"
        font_size: 20

    MDTextField:
        id: word_input
        hint_text: 'Name'
        multiline: False
        size_hint: (1, .5)
        halign: "center"
        valign: "middle"
        font_size: 32

    MDRaisedButton: 
        size_hint: (1, .5)
        font_size: 32
        text: 'Add Record'
        on_press: app.add()

What should I do to fix the problem?

0 Answers
Related