Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I want the textbox to automatically delete previous output so I can type a full sentence without every letter printing to the textbox. However, it repeats itself going all the way down, so when I hit my save button it records every line to my clipboard.

I have tried using the Tkinter text delete: text.delete(1.0,END). It does not delete anything, however.

class ExamplePanel(wx.Panel):

    def __init__(self, parent):

        wx.Panel.__init__(self, parent, size=(3000,2000))

        self.cipherText = wx.StaticText(self, label="Ciphered Text: ", pos=(20, 30))

    #A multiline TextCtrl- Shows the events in the program. 

    #I think this might be where the problem is but I do not know how to 

    #get it to only print once, perhaps after the user hits "enter" or something.

        self.logger = wx.TextCtrl(self, pos=(300,20), size=(200,300), style=wx.TE_MULTILINE | wx.TE_READONLY) 

        self.encrypt = wx.StaticText(self, label="Encryptor: ", pos=(20,60))

        self.encryptEdit = wx.TextCtrl(self, value="", pos=(150, 60), size=(140,-1))

        self.Bind(wx.EVT_TEXT, self.EncText, self.encryptEdit)

        self.Bind(wx.EVT_CHAR, self.EncChar, self.encryptEdit)

    def EncText(self,event):

        result = ''

        message = event.GetString()

        for i in range(0, len(message)):

            result = result + chr(ord(message[i]) - 2)

        result = result.replace(chr(30), ' ')

        print(result + '\n\n')

        self.logger.AppendText(result + '\n\n')

As described above, my goal is to have it empty the textbox whenever a new keystroke is made so that it doesn't repeat going all the way down.

1 Answer

0 votes
by (25.1k points)

The problem is that you are using.ApppendText(result + '\n\n') which is adding text at the end of the log. Since you want to empty the textbox you should use .SetValue(result + '\n\n'). It should replace text in TextCtrl

Related questions

0 votes
1 answer
asked Feb 11, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer
asked Jan 21, 2020 in Python by Rajesh Malhotra (19.9k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...