Hi I just started learning wxPython
I wanted to know how I could do this in wxPython
self.listbox.de lete(0, END)
for item in self.results:
self.listbox.in sert(END, item)
I don't know but I think the insert and delete things here are specific of
Tkinter which I have been studying for the last little while
Anyhelp would be cool 5 10599
Andrew wrote: Hi I just started learning wxPython
I wanted to know how I could do this in wxPython
self.listbox.de lete(0, END) for item in self.results: self.listbox.in sert(END, item)
I don't know but I think the insert and delete things here are specific of Tkinter which I have been studying for the last little while
# make a list box with default choices
box = wxListBox(self, -1, choices=['a','b','c'])
# append a new entry
box.Append('d')
# reset the listbox to something else
box.Set(['1','2','3'])
# delete the second entry selection
box.Delete(1)
# get the index of currently selected entry
print box.GetSelectio n()
# get the string that is selected
print box.GetStringSe lection()
# make a callback for when an entry is selected
def listboxhandler( evt):
box = evt.GetEventObj ect()
print box.GetSelectio n(), "selected index"
print box.GetStringSe lection(), "selected item"
EVT_LISTBOX(box , box.GetId(), listboxhandler)
full little program
############### ############### ############### ##############
from wxPython.wx import *
class T(wxFrame):
def __init__(self, parent, id, title):
print "calling init"
wxFrame.__init_ _(self, parent, id, title)
self.mainsizer = self.sizer = wxBoxSizer(wxVE RTICAL)
# make a list box with default choices
box = wxListBox(self, -1, choices=['a','b','c'])
# append a new entry
box.Append('d')
# reset the listbox to something else
box.Set(['1','2','3'])
box.Delete(0)
print box.GetSelectio ns()
self.sizer.Add( box, 0, wxEXPAND)
self.SetSizer(s elf.sizer)
def listboxhandler( evt):
box = evt.GetEventObj ect()
print box.GetSelectio n(), "selected index"
print box.GetStringSe lection(), "selected item"
EVT_LISTBOX(box , box.GetId(), listboxhandler)
app = wxPySimpleApp()
foo = T(None, -1, "hello")
print foo
foo.Show()
app.MainLoop()
Anyhelp would be cool
Hi thanks for your help but I am still having problems basically I am using
a button to connect to a Database and I want to display the data from the
database into the listbox
Here is the code I am using for the button
def OnB2Button(self , event):
self.db = MySQLdb.connect ("localhost" , "", "", "guestbook" )
global db
self.c = self.db.cursor( )
self.c.execute( "SELECT * FROM guests;")
self.results = self.c.fetchall ()
# Here is where I don't know what to do I want to be able to get the
data from self.results and display it in the listbox
self.listbox.Ap pend('')
self.listbox.Se t([''])
self.listbox.De lete(0)
print self.listbox.Ge tSelections()
self.sizer.Add( self.listbox, 0, wxEXPAND)
self.Set.Sizer( self.sizer)
Thank you again for your help
Cheers
Andrew
Andrew wrote: Hi thanks for your help but I am still having problems basically I am using a button to connect to a Database and I want to display the data from the database into the listbox Here is the code I am using for the button
self.c = self.db.cursor( ) self.c.execute( "SELECT * FROM guests;") self.results = self.c.fetchall () # Here is where I don't know what to do I want to be able to get the data from self.results and display it in the listbox self.listbox.Ap pend('') self.listbox.Se t([''])
It looks as though you are putting nothing in the listbox.
Append('') adds a blank
and listbox.Set(['']) replaces the listbox with a blank.
Try:
for x in self.results:
self.listbox.Ap pend(x[0])
Brian
Hi I had tried something similiar to that earlier.
I typed what you wrote
for x in self.results:
self.listbox.Ap pend(x[0])
and I got the same error as what I had tried earlier
Traceback (most recent call last):
File "S:\GUI\MYSQL\m ysqlgui.py", line 65, in OnB2Button
self.listbox.Ap pend(x[0])
File "F:\Python22\Li b\site-packages\wxPyth on\controls.py" , line 78, in
Append
val = controlsc.wxCon trolWithItems_A ppend(self, *_args, **_kwargs)
TypeError: String or Unicode type required
Any help is alway's appreciated
"Andrew" <na> writes: I typed what you wrote
for x in self.results: self.listbox.Ap pend(x[0])
and I got the same error as what I had tried earlier
Traceback (most recent call last): File "S:\GUI\MYSQL\m ysqlgui.py", line 65, in OnB2Button self.listbox.Ap pend(x[0]) File "F:\Python22\Li b\site-packages\wxPyth on\controls.py" , line 78, in Append val = controlsc.wxCon trolWithItems_A ppend(self, *_args, **_kwargs) TypeError: String or Unicode type required
Any help is alway's appreciated
Your database query is returning a list of tuples, where each element
in the tuple is a column from your database that is part of the query
(or all columns in the table with your query of *). The tuple is not
a string, which is what the wxListBox understands how to display.
I expect that if you change the code to:
self.listbox.Ap pend(str(x[0]))
you'll get rid of the error, since that will provide a string
representation of the tuple x[0], but I also expect it won't be
exactly what you want depending on the database columns, and/or the
way certain data types automatically turn themselves into strings.
In the end you'll probably want to process each entry in 'results'
according to your own desires for display purposes, formatting an
appropriate string to be put into the ListBox. You may also find that
using a wxListCtrl in wxLC_REPORT mode fits well since it will make it
simpler to divide the columns of data (either that or a wxGrid,
although wxGrid is probably overkill).
-- David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
by: Jeff |
last post by:
I need to insert into a table multiple item of a listbox. (item.text and item.value
Right now, I'm using an OleDBConnection with Access, a Command(Insert string) and parameters. I don't see how an ExecuteNonQuery() would fit in a loop ? Must be a simple solution out there
dim Item as listIte
for each Item in ListBox1.Item
INSERT INTO...
|
by: Big E |
last post by:
I'm using ASP.Net and SQL Server 2000. I'm trying to insert or update
records from a multiselect listbox. How can I get the contents of the
listbox if there is more than one selected and update that into the
database. But most important how do I update or insert those records.
Any articles or ideas would be appreciated.
Thanks.
Big e
|
by: Brad Baker |
last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL
database. At the top of the page I have the following code:
<%@ Page Language="C#" Debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<script language="c#" runat="server">
public void Page_Load(object sender,...
|
by: shuf |
last post by:
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):
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# generated by wxGlade 0.4.1 on Thu Mar 22 12:15:29 2007...
| |
by: rahulnag22 |
last post by:
Hi,
Is it possible to have different items in a listbox in different
colors? Or is it just one color for all items in a listbox?
Thanks
Rahul
|
by: Marcpp |
last post by:
Hi, I need add to a listbox a list of items extracted from a database.
This is that I've do:
class tasques(wx.Frame):
def __init__(self, *args, **kwds):
.....
self.list_box_1_copy = wx.ListBox(self, -1, choices=,
style=wx.LB_SINGLE|wx.LB_ALWAYS_SB)
....
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |