| | |
Tree control with check boxes
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Care to elaborate... a lot? I mean it'd help if you mentioned what GUI module you're using, for a start.
Mir's Fuselage
Because what's not to like about being killed by a toilet seat from Mir's atmospheric re-entry?
Because what's not to like about being killed by a toilet seat from Mir's atmospheric re-entry?
•
•
Join Date: Feb 2008
Posts: 198
Reputation:
Solved Threads: 0
We are using this code.We are unable to append check box corresponding to each node.
For example, I need check boxes for node named LINUX,FreeBSD etc and hencelikewise.
please see attachment.
******************-************************-*******************************-*
********************-**************************-*********************
Editors note: Please use the [code=python] and [/code] tag pair to enclose your python code.
For example, I need check boxes for node named LINUX,FreeBSD etc and hencelikewise.
please see attachment.
******************-************************-*******************************-*
python Syntax (Toggle Plain Text)
import wx class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(450, 350)) hbox = wx.BoxSizer(wx.HORIZONTAL) vbox = wx.BoxSizer(wx.VERTICAL) panel1 = wx.Panel(self, -1) panel2 = wx.Panel(self, -1) self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS) root = self.tree.AddRoot('Programmer') os = self.tree.AppendItem(root, 'Operating Systems') pl = self.tree.AppendItem(root, 'Programming Languages') tk = self.tree.AppendItem(root, 'Toolkits') self.tree.AppendItem(os, 'Linux') self.tree.AppendItem(os, 'FreeBSD') self.tree.AppendItem(os, 'OpenBSD') self.tree.AppendItem(os, 'NetBSD') self.tree.AppendItem(os, 'Solaris') cl = self.tree.AppendItem(pl, 'Compiled languages') sl = self.tree.AppendItem(pl, 'Scripting languages') self.tree.AppendItem(cl, 'Java') self.tree.AppendItem(cl, 'C++') self.tree.AppendItem(cl, 'C') self.tree.AppendItem(cl, 'Pascal') self.tree.AppendItem(sl, 'Python') self.tree.AppendItem(sl, 'Ruby') self.tree.AppendItem(sl, 'Tcl') self.tree.AppendItem(sl, 'PHP') self.tree.AppendItem(tk, 'Qt') self.tree.AppendItem(tk, 'MFC') self.tree.AppendItem(tk, 'wxPython') self.tree.AppendItem(tk, 'GTK+') self.tree.AppendItem(tk, 'Swing') self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=1) self.display = wx.StaticText(panel2, -1, '',(10,10), style=wx.ALIGN_CENTRE) vbox.Add(self.tree, 1, wx.EXPAND) hbox.Add(panel1, 1, wx.EXPAND) hbox.Add(panel2, 1, wx.EXPAND) panel1.SetSizer(vbox) self.SetSizer(hbox) self.Centre() def OnSelChanged(self, event): item = event.GetItem() self.display.SetLabel(self.tree.GetItemText(item)) class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'treectrl.py') frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(0) app.MainLoop()
********************-**************************-*********************
Editors note: Please use the [code=python] and [/code] tag pair to enclose your python code.
Last edited by vegaseat; Jun 6th, 2008 at 1:53 pm. Reason: code tags
Why not just create checkboxes, hide them, and then on the event of a tree node expansion, show the corresponding checkboxes?
Mir's Fuselage
Because what's not to like about being killed by a toilet seat from Mir's atmospheric re-entry?
Because what's not to like about being killed by a toilet seat from Mir's atmospheric re-entry?
•
•
Join Date: Dec 2006
Posts: 1,063
Reputation:
Solved Threads: 299
Although I don't use wxPython, you should be able to use a dictionary to clean up the code. Something like this. Again I don't use this toolkit so it may require tuning.
Python Syntax (Toggle Plain Text)
import wx class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(450, 350)) hbox = wx.BoxSizer(wx.HORIZONTAL) vbox = wx.BoxSizer(wx.VERTICAL) panel1 = wx.Panel(self, -1) panel2 = wx.Panel(self, -1) self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS) root = self.tree.AddRoot('Programmer') os = self.tree.AppendItem(root, 'Operating Systems') pl = self.tree.AppendItem(root, 'Programming Languages') tk = self.tree.AppendItem(root, 'Toolkits') root_dict = {} root_dict[os] = ('Linux', 'FreeBSD', 'OpenBSD', 'NetBSD', 'Solaris') root_dict[tk] = ('Qt', 'MFC', 'wxPython', 'GTK+', 'Swing') for index in root_dict.keys(): for item in root_dict[index]: self.tree.AppendItem(index, item) cl = self.tree.AppendItem(pl, 'Compiled languages') sl = self.tree.AppendItem(pl, 'Scripting languages') pl_dict = {} pl_dict[cl] = ('Java', 'C++', 'C', 'Pascal') pl_dict[sl] = ('Python', 'Ruby', 'Tcl', 'PHP') for index in pl_dict.keys(): for item in pl_dict[index]: self.tree.AppendItem(index, item) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=1) self.display = wx.StaticText(panel2, -1, '',(10,10), style=wx.ALIGN_CENTRE) vbox.Add(self.tree, 1, wx.EXPAND) hbox.Add(panel1, 1, wx.EXPAND) hbox.Add(panel2, 1, wx.EXPAND) panel1.SetSizer(vbox) self.SetSizer(hbox) self.Centre() def OnSelChanged(self, event): item = event.GetItem() self.display.SetLabel(self.tree.GetItemText(item)) class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'treectrl.py') frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(0) app.MainLoop()
![]() |
Similar Threads
- tree control view with check box (C#)
- Positioning a Group Box at Runtime - Help (Visual Basic 4 / 5 / 6)
- Problem with wx.TreeCtrl (Python)
Other Threads in the Python Forum
- Previous Thread: File IO and pictures
- Next Thread: cs help
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied apache application argv beginner book change code color dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime print program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






