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

时间:2019-03-24 05:14:58

标签: wxpython

button1

在这里,我将OkButton绑定到button2并将ynButton绑定到int main() { int temp=0,x,n,i; cin>>x; while(x--) { cin>>n; queue<int> q; for(i=1;i<=n;i++) q.push(i); while(q.size()!=1) { q.pop(); temp=q.front(); q.pop(); q.push(temp); } cout<<temp; } return 0; } ,假设发生的是,当我在第一个面板中键入一个单词时,它应该出现在第二个面板中一个加密,然后再次解密。

1 个答案:

答案 0 :(得分:0)

类似这样的东西:

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()