468,136 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

wxpython listbox help

8
Hello,

I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegroundColour() (this method does not appear to do anything):

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. # generated by wxGlade 0.4.1 on Thu Mar 22 12:15:29 2007
  4.  
  5. import wx
  6.  
  7. class MyFrame(wx.Frame):
  8.     def __init__(self, *args, **kwds):
  9.         # begin wxGlade: MyFrame.__init__
  10.         kwds["style"] = wx.DEFAULT_FRAME_STYLE
  11.         wx.Frame.__init__(self, *args, **kwds)
  12.         self.list_box_1 = wx.ListBox(self, -1, choices=["One", "Two"])
  13.  
  14.         self.__set_properties()
  15.         self.__do_layout()
  16.  
  17.         self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list_box_1)
  18.         # end wxGlade
  19.  
  20.     def __set_properties(self):
  21.         # begin wxGlade: MyFrame.__set_properties
  22.         self.SetTitle("frame_1")
  23.         self.list_box_1.SetSelection(0)
  24.         # end wxGlade
  25.  
  26.     def __do_layout(self):
  27.         # begin wxGlade: MyFrame.__do_layout
  28.         sizer_1 = wx.BoxSizer(wx.VERTICAL)
  29.         sizer_1.Add(self.list_box_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
  30.         self.SetAutoLayout(True)
  31.         self.SetSizer(sizer_1)
  32.         sizer_1.Fit(self)
  33.         sizer_1.SetSizeHints(self)
  34.         self.Layout()
  35.         # end wxGlade
  36.  
  37.     def OnSelect(self, event): # wxGlade: MyFrame.<event_handler>
  38.         self.list_box_1.SetItemForegroundColour(0,wx.RED)
  39.         self.list_box_1.SetItemForegroundColour(1,wx.BLUE)
  40.  
  41. # end of class MyFrame
  42.  
  43.  
  44. if __name__ == "__main__":
  45.     app = wx.PySimpleApp(0)
  46.     wx.InitAllImageHandlers()
  47.     frame_1 = MyFrame(None, -1, "")
  48.     app.SetTopWindow(frame_1)
  49.     frame_1.Show()
  50.     app.MainLoop()
However, I am able to set the font color of all the elements with SetForegroundColour(). I want to be able to have each color represent the current state of an element. I know that I can do this with a listctrl, but I wanted to try to do it with a listbox. Any help is greatly appreciated.

Thanks in advance,
Stephen
Mar 22 '07 #1
6 5824
bartonc
6,596 Expert 4TB
Hello,

I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegroundColour() (this method does not appear to do anything):

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. # generated by wxGlade 0.4.1 on Thu Mar 22 12:15:29 2007
  4.  
  5. import wx
  6.  
  7. class MyFrame(wx.Frame):
  8.     def __init__(self, *args, **kwds):
  9.         # begin wxGlade: MyFrame.__init__
  10.         kwds["style"] = wx.DEFAULT_FRAME_STYLE
  11.         wx.Frame.__init__(self, *args, **kwds)
  12.         self.list_box_1 = wx.ListBox(self, -1, choices=["One", "Two"])
  13.  
  14.         self.__set_properties()
  15.         self.__do_layout()
  16.  
  17.         self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list_box_1)
  18.         # end wxGlade
  19.  
  20.     def __set_properties(self):
  21.         # begin wxGlade: MyFrame.__set_properties
  22.         self.SetTitle("frame_1")
  23.         self.list_box_1.SetSelection(0)
  24.         # end wxGlade
  25.  
  26.     def __do_layout(self):
  27.         # begin wxGlade: MyFrame.__do_layout
  28.         sizer_1 = wx.BoxSizer(wx.VERTICAL)
  29.         sizer_1.Add(self.list_box_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
  30.         self.SetAutoLayout(True)
  31.         self.SetSizer(sizer_1)
  32.         sizer_1.Fit(self)
  33.         sizer_1.SetSizeHints(self)
  34.         self.Layout()
  35.         # end wxGlade
  36.  
  37.     def OnSelect(self, event): # wxGlade: MyFrame.<event_handler>
  38.         self.list_box_1.SetItemForegroundColour(0,wx.RED)
  39.         self.list_box_1.SetItemForegroundColour(1,wx.BLUE)
  40.  
  41. # end of class MyFrame
  42.  
  43.  
  44. if __name__ == "__main__":
  45.     app = wx.PySimpleApp(0)
  46.     wx.InitAllImageHandlers()
  47.     frame_1 = MyFrame(None, -1, "")
  48.     app.SetTopWindow(frame_1)
  49.     frame_1.Show()
  50.     app.MainLoop()
However, I am able to set the font color of all the elements with SetForegroundColour(). I want to be able to have each color represent the current state of an element. I know that I can do this with a listctrl, but I wanted to try to do it with a listbox. Any help is greatly appreciated.

Thanks in advance,
Stephen
I can't find SetItemForegroundColour() anywhere in the docs.
For the foreground, you want SetItemTextColour()
Both SetItemTextColour() and SetItemBackgroundColour() is ListCtrl and TreeCtrl specific.
Mar 22 '07 #2
shuf
8
I can't find SetItemForegroundColour() anywhere in the docs.
For the foreground, you want SetItemTextColour()
Both SetItemTextColour() and SetItemBackgroundColour() is ListCtrl and TreeCtrl specific.
I found the method specified here. Is this the right place to be looking?
Mar 23 '07 #3
bartonc
6,596 Expert 4TB
I found the method specified here. Is this the right place to be looking?
The site is good, but is layed out in a manner that is a little confusing. The docs that I use are for the C++ package, but have some wxPython notes where they are needed. These docs come from win32-docs-demos download here. These are the easiest to follow if you don't mind thinking in C++ just a little.
Mar 23 '07 #4
shuf
8
... if you don't mind thinking in C++ just a little.
After working in C and C++ for a couple of years thinking in C++ is a nice break :). This is my first real project in Python, and I really enjoy it and all the help I have recieved!
Mar 23 '07 #5
bartonc
6,596 Expert 4TB
After working in C and C++ for a couple of years thinking in C++ is a nice break :). This is my first real project in Python, and I really enjoy it and all the help I have recieved!
That's great to hear! Drop in any time for what ever python help you need. That's what TheScripts Python Forum is all about!
Mar 23 '07 #6
bartonc
6,596 Expert 4TB
Hello,

I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegroundColour() (this method does not appear to do anything):
By the way, wxPython version 2.8 is out and stable. There are no issues that I've discovered (using Boa Constructor) in upgrading.
Mar 23 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Daniel Ehrenberg | last post: by
5 posts views Thread by Andrew | last post: by
7 posts views Thread by SeeBelow | last post: by
1 post views Thread by Adam Endicott | last post: by
1 post views Thread by fooooo | last post: by
reply views Thread by Iain King | last post: by
1 post views Thread by Bailu | last post: by
8 posts views Thread by Janwillem | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.