在wxpython中拆分字符串输入

时间:2017-07-24 17:22:31

标签: python-2.7 python-3.x split wxpython

我已经创建了一个文本输入对话框,用户将以这种格式A,B,C放置一些信息 现在我想拆分这个字符串,以便我可以将它用于更进一步的目的。当我尝试这个代码时,它给我错误“全局名称'名称'未定义” 这是pastebin链接

import wx
class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Dialog Test",size=(500,400))
        self.panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.button = wx.Button(self.panel, label="Click me")
        sizer.Add(self.button, 0, wx.EXPAND | wx.ALL, 10)
        self.panel.SetSizer(sizer)
        self.Bind(wx.EVT_BUTTON, self.OnButton)

    def OnButton(self,event):
        dlg = GetData(parent = self.panel)
        dlg.ShowModal()
        dlg.Destroy()

class GetData(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, wx.ID_ANY, "Name Input", size= (650,220))
        self.panel = wx.Panel(self,wx.ID_ANY)
        self.lblname = wx.StaticText(self.panel, label="Name", pos=(20,20))
        self.name = wx.TextCtrl(self.panel, value="", pos=(110,20), size=(500,-1))
        self.saveButton =wx.Button(self.panel, label="Save", pos=(110,160))
        self.closeButton =wx.Button(self.panel, label="Cancel", pos=(210,160))
        self.saveButton.Bind(wx.EVT_BUTTON, self.SaveConnString)
        self.closeButton.Bind(wx.EVT_BUTTON, self.OnQuit)
        self.Bind(wx.EVT_CLOSE, self.OnQuit)
        self.Show()

    def OnQuit(self, event):
        self.result_name = None
        self.Destroy()

    def SaveConnString(self, event):
        self.result_name = self.name.GetValue()
        print name.split( )
        print name.split(' ', 1 )
        self.Destroy()

app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

1 个答案:

答案 0 :(得分:1)

它只是一个变量命名的东西:

def SaveConnString(self, event):
    name = self.name.GetValue()
    print name.split( )
    print name.split(' ', 1 )

def SaveConnString(self, event):
    self.result_name = self.name.GetValue()
    print self.result_name.split( )
    print self.result_name.split(' ', 1 )