使用 wxpython 如何获取我在一个 Textctrl 面板中键入的单词在另一个面板中显示为加密,反之亦然

using wxpython How to get words I type in one Textctrl panel to appear encrypted in the other and vise versa

y = list(jumble)
x = list(alphabet)
self.button1.Bind(wx.EVT_BUTTON, self.OkButton)
self.button2.Bind(wx.EVT_BUTTON, self.YnButton)
i = 0

def OkButton(self, e ):
    global str1
    for i in range(len(x)):
    f1 = x[i]
    f2 = y[i]
    i += 1
    str2 = str1.replace(f1,f2)
    str1 = str2
    self.result.SetLabel(self.editname.GetValue())

def YnButton(self, e):
    global str1
    i = 0
    for i in range(len(x)):
    f1 = x[i]
    f2 = y[i]
    i += 1
    str2 = str1.replace(f2,f1)
    str1 = str2
    self.result.SetLabel(self.editname.GetValue())

在这里我将 button1 绑定到 OkButton 并将 button2 绑定到 ynButton ,假设发生的是当我在第一个面板中键入一个单词时它应该出现在第二个加密然后再次解密。

像这样:

import wx

class MyWin(wx.Frame):
    """
    Creates the GUI
    """
    def __init__(self):
        super().__init__(None, title="My Enigma Machine", style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX))
        #### Widgets
        ## Panel
        self.panel = wx.Panel(self)
        ## Buttons
        self.buttonEncript = wx.Button(self.panel, label='Encript')
        self.buttonDecript = wx.Button(self.panel, label='Decript')
        ## TextCtrl
        self.tcToEncript = wx.TextCtrl(self.panel, value="", size=(515, 22))
        self.tcToDecript = wx.TextCtrl(self.panel, value="", size=(515, 22))
        #### Sizers
        self.sizer = wx.GridBagSizer(1, 1)
        self.sizer.Add(self.tcToEncript,     pos=(0, 0), border=2, flag=wx.EXPAND|wx.ALL)
        self.sizer.Add(self.buttonEncript, pos=(0, 1), border=2, flag=wx.ALIGN_CENTER|wx.ALL)
        self.sizer.Add(self.tcToDecript,     pos=(1, 0), border=2, flag=wx.EXPAND|wx.ALL)
        self.sizer.Add(self.buttonDecript, pos=(1, 1), border=2, flag=wx.ALIGN_CENTER|wx.ALL)
        self.panel.SetSizer(self.sizer)
        self.sizer.Fit(self)
        #### Bind
        self.buttonEncript.Bind(wx.EVT_BUTTON, self.OnEncript)
        self.buttonDecript.Bind(wx.EVT_BUTTON, self.OnDecript)

    #### Methods of the class
    def OnEncript(self, event):
        """
        Encript the text. It will just change the case of each letter
        """
        string = self.tcToEncript.GetValue()
        stringEncripted = string.swapcase()
        self.tcToDecript.SetValue(stringEncripted)

    def OnDecript(self, event):
        """
        Same as OnEncript
        """
        string = self.tcToDecript.GetValue()
        stringDecripted = string.swapcase()
        self.tcToEncript.SetValue(stringDecripted)       

if __name__ == '__main__':
    app = wx.App()
    frame = MyWin()
    frame.Show()
    app.MainLoop()