473,609 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxpython listbox help

8 New Member
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 SetItemForegrou ndColour() (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 SetForegroundCo lour(). 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 6206
bartonc
6,596 Recognized Expert Expert
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 SetItemForegrou ndColour() (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 SetForegroundCo lour(). 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 SetItemForegrou ndColour() anywhere in the docs.
For the foreground, you want SetItemTextColo ur()
Both SetItemTextColo ur() and SetItemBackgrou ndColour() is ListCtrl and TreeCtrl specific.
Mar 22 '07 #2
shuf
8 New Member
I can't find SetItemForegrou ndColour() anywhere in the docs.
For the foreground, you want SetItemTextColo ur()
Both SetItemTextColo ur() and SetItemBackgrou ndColour() 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 Recognized Expert Expert
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 New Member
... 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 Recognized Expert Expert
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 Recognized Expert Expert
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 SetItemForegrou ndColour() (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

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

Similar topics

5
4188
by: Daniel Ehrenberg | last post by:
I'm trying to learn wxPython, but I can't seem to find much documentation. The wxPython website says that all advanced (and even some basic) documentation for wxPython is only available in C++ syntax in the main wxWindows documentation. It also says that the samples will help, but I can't seem to make sense of them. Should I just use a not-as-good GUI like Tkinter or a not-as-common one like Anygui or PyUI if I want to have documentation?...
5
10602
by: Andrew | last post by:
Hi I just started learning wxPython I wanted to know how I could do this in wxPython self.listbox.delete(0, END) for item in self.results: self.listbox.insert(END, item)
7
11893
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of wxPython. Mitchell Timin -- "Many are stubborn in pursuit of the path they have chosen, few in
1
3492
by: Adam Endicott | last post by:
I'm having some trouble using an HtmlListBox with a GridBagSizer. I'm not sure how best to explain what's happening, but it seems that every time my frame gets resized, the HtmlListBox grows taller, even when the resize is only horizontal, or makes the frame smaller. I'm pretty new to GUI layout and wxPython, so hopefully I'm doing something obviously wrong. Here's a short runnable code sample showing my basic layout (I'm using python...
1
2167
by: fooooo | last post by:
How do I center each item in the ListBox widget? Also, is it possible to change the color of the selected item? right now it uses the OSes color. I would like it to be consistant on every machine.
0
943
by: Iain King | last post by:
I'm making a program to view log files. The main display is a multi column listbox. I want to add combobox filters above the listbox headers. The filters contain each unique instance in the list column below it, and if any filter has text selected in it then the listbox will only display rows in which the relevant column contains that text (MS Excel's Autofilter, basically). I need to get the comboboxes to be positioned directly above...
1
4589
by: Bailu | last post by:
Hi, I am a newbie in wxPython and doing a program with ListBox, I want to select and deselect items in this box, I have use self.devlist = wx.ListBox(self, style=wx.LB_MULTIPLE) self.Bind(wx.EVT_LISTBOX, self.select_dev, self.devlist) to create this box, but don't know how to implement self.select_dev
8
3712
by: Janwillem | last post by:
Is there a way to force the wx.FileDialog to show as default the thumbnails vie in stead of list view? thanks, janwillem
3
2303
by: Soren | last post by:
Hi, Id like to make my own special listbox.. I want to able (at the push of a button) to add another item to my special listbox... each item is a panel with a label, some buttons and maybe a text control. I've tried adding a new panel object with the stuff i want to the sizer i'm using for my listbox (which is a panel which can contain other panels)... and then run update() and refresh() on everything... But it doesn't work.. i see a...
0
8076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8406
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2531
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.