Python 2.7 如何在列表框中打印TextEntryDialog值?
我想知道如何使用文本输入对话框中的值 从 类,例如在Python 2.7 如何在列表框中打印TextEntryDialog值?,python-2.7,wxpython,Python 2.7,Wxpython,我想知道如何使用文本输入对话框中的值 从 类,例如在wx.ListBox中,asd正在右侧打印 一边 代码如下: import wx class main_window(wx.Frame): def SetOutput(self, output): self.output = output def OnSelChanged(self, event): "
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()
您只需将输入值插入列表框
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()
你能指定你想做什么吗?是否要从“文本输入”对话框中获取输入值?是的,我想通过输入框获取输入,并在类外使用。@user333736是的,您可以尝试使用答案中的代码。在该代码中,每个选择上的树都显示相同的内容。如何为不同的树选择分配不同的函数?例如,第一次选择显示文本输入对话框,第二次选择显示opendir功能。