2014-02-20 6 views
0

Я хочу знать, как я могу использовать значение в диалоге въездного текста из функции def textentry в функции класса, такие как в wx.ListBox где КАН печати на правой стороне .Как напечатать значение TextEntryDialog в поле списка?

Вот код:

 import wx 

     class main_window(wx.Frame): 
      def SetOutput(self, output): 
       self.output = output 
      def OnSelChanged(self, event): 
       """ 
       If an output function is defined, we try to print some 
       informative, interesting and thought-provoking stuff to it. 
       If it has a __doc__ string, we print it. If it's a function or 
       unbound class method, we attempt to find the python source. 
        """ 
       item = event.GetItem() 
      def textentry(self, event): 
       dlg = wx.TextEntryDialog(self, 'Enter URL','URL Parsing') 
       dlg.SetValue("Default") 
       if dlg.ShowModal() == wx.ID_OK: 
        self.SetStatusText('You entered: %s\n' % dlg.GetValue()) 
        return (dlg.GetValue()) 
      def opendir(self, event): 
       dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) 
       if dlg.ShowModal() == wx.ID_OK: 
        self.SetStatusText('You selected: %s\n' % dlg.GetPath()) 
       dlg.Destroy() 
      def OnExit(self,e): 
       self.Close(True) 
      def __init__(self, parent, title): 
       wx.Frame.__init__(self, parent, title=title, size=(500, 500),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE) 
       status=self.CreateStatusBar() 
       splitter = wx.SplitterWindow(self, style=wx.SP_3D) 
       splitter.SetMinimumPaneSize(1) 
       menubar=wx.MenuBar() 
       first=wx.Menu() 
       second=wx.Menu() 
       third=wx.Menu() 
       first.Append(106,"a","a") 
       first.Append(104,"Open","Browse") 
       first.Append(100,"anything","yup") 
       first.Append(105,"Exit","Quit") 
       second.Append(101,"s","s") 
       menubar.Append(first,"File") 
       menubar.Append(second,"Tool") 
       menubar.Append(third,"Contact us") 
       self.SetMenuBar(menubar) 
       self.Bind(wx.EVT_MENU, self.textentry, id=106) 
       self.Bind(wx.EVT_MENU, self.OnExit, id=105) 
       self.Bind(wx.EVT_MENU, self.opendir, id=104) 
       self.tree = wx.TreeCtrl(splitter,1, style=wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS) 
       """ 
       If an output function is defined, we try to print some 
       informative, interesting and thought-provoking stuff to it. 
       If it has a __doc__ string, we print it. If it's a function or 
       unbound class method, we attempt to find the python source. 
        """ 
       root = self.tree.AddRoot('wd') 
       os = self.tree.AppendItem(root, 'sa') 
       cl = self.tree.AppendItem(root, 'a') 
       self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree) 
       cunt=wx.ListBox(splitter, -1, (100,100), (100,100), 'asd', wx.LB_SINGLE) 
       cunt.SetSelection(1) 
       splitter.SplitVertically(self.tree, cunt,200) 
       splitter.SetSashPosition(180, True) 
       self.Show(True) 
       """ 
       If an output function is defined, we try to print some 
       informative, interesting and thought-provoking stuff to it. 
       If it has a __doc__ string, we print it. If it's a function or 
       unbound class method, we attempt to find the python source. 
        """ 
     class App(wx.App): 
      def OnInit(self): 
       frame = main_window(None, 'S2A vulnerability Scanner') 
       return True 


     if __name__ == '__main__': 
      app = App(0) 
      app.MainLoop() 
+0

Можете ли вы указать, что вы хотите сделать ? Вы хотите получить входное значение из диалогового окна ввода текста? –

+0

да, я хочу получить ввод через поле ввода и использовать его вне класса. – user3333736

+0

@ user333736 да, вы можете попробовать с кодом в ответе. –

ответ

0

Вам просто нужно вставить значение ввода в поле списка.

  1. использование self.cunt заменить cunt
  2. в textentry использование self.cunt.Insert(val, 0) в вставить значение входного в список

Попробуйте следующий код:

import wx 

class main_window(wx.Frame): 
    def SetOutput(self, output): 
     self.output = output 
    def OnSelChanged(self, event): 
     """ 
     If an output function is defined, we try to print some 
     informative, interesting and thought-provoking stuff to it. 
     If it has a __doc__ string, we print it. If it's a function or 
     unbound class method, we attempt to find the python source. 
      """ 
     item = event.GetItem() 
    def textentry(self, event): 
     dlg = wx.TextEntryDialog(self, 'Enter URL','URL Parsing') 
     dlg.SetValue("Default") 
     if dlg.ShowModal() == wx.ID_OK: 
      val = dlg.GetValue() 
      self.SetStatusText('You entered: %s\n' % val) 
      self.cunt.Insert(val, 0) 
      return (dlg.GetValue()) 
    def opendir(self, event): 
     dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) 
     if dlg.ShowModal() == wx.ID_OK: 
      self.SetStatusText('You selected: %s\n' % dlg.GetPath()) 
     dlg.Destroy() 
    def OnExit(self,e): 
     self.Close(True) 
    def __init__(self, parent, title): 
     wx.Frame.__init__(self, parent, title=title, size=(500, 500),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE) 
     status=self.CreateStatusBar() 
     splitter = wx.SplitterWindow(self, style=wx.SP_3D) 
     splitter.SetMinimumPaneSize(1) 
     menubar=wx.MenuBar() 
     first=wx.Menu() 
     second=wx.Menu() 
     third=wx.Menu() 
     first.Append(106,"a","a") 
     first.Append(104,"Open","Browse") 
     first.Append(100,"anything","yup") 
     first.Append(105,"Exit","Quit") 
     second.Append(101,"s","s") 
     menubar.Append(first,"File") 
     menubar.Append(second,"Tool") 
     menubar.Append(third,"Contact us") 
     self.SetMenuBar(menubar) 
     self.Bind(wx.EVT_MENU, self.textentry, id=106) 
     self.Bind(wx.EVT_MENU, self.OnExit, id=105) 
     self.Bind(wx.EVT_MENU, self.opendir, id=104) 
     self.tree = wx.TreeCtrl(splitter,1, style=wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS) 
     """ 
     If an output function is defined, we try to print some 
     informative, interesting and thought-provoking stuff to it. 
     If it has a __doc__ string, we print it. If it's a function or 
     unbound class method, we attempt to find the python source. 
      """ 
     root = self.tree.AddRoot('wd') 
     os = self.tree.AppendItem(root, 'sa') 
     cl = self.tree.AppendItem(root, 'a') 
     self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree) 

     self.cunt=wx.ListBox(splitter, -1, (100,100), (100,100), 'asd', wx.LB_SINGLE) 
     self.cunt.SetSelection(1) 
     splitter.SplitVertically(self.tree, self.cunt,200) 
     splitter.SetSashPosition(180, True) 
     self.Show(True) 
     """ 
     If an output function is defined, we try to print some 
     informative, interesting and thought-provoking stuff to it. 
     If it has a __doc__ string, we print it. If it's a function or 
     unbound class method, we attempt to find the python source. 
      """ 
class App(wx.App): 
    def __init__(self, redirect): 
     wx.App.__init__(self, redirect) 

    def OnInit(self): 
     frame = main_window(None, 'S2A vulnerability Scanner') 
     return True 


if __name__ == '__main__': 
    app = App(0) 
    app.MainLoop() 
+0

в этом коде дерево каждого из них показывает то же самое, как я могу назначить разные функции для разных вариантов дерева? например, при первом выборе он отображает диалоговое окно ввода текста, а во втором показывает opendir fuction. – user3333736

Смежные вопросы