我想知道如何使用文本输入对话框中的值
来自def textentry
函数中的def __init__
函数
例如在wx.ListBox
中的类,其中asd在右侧打印
侧。
以下是代码:
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)
您只需将输入值插入列表框即可。
self.cunt
替换cunt
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()