[Tutor] Help with AppendText Syntax
richard
python at keep-trying.com
Sun Dec 21 11:18:17 EST 2003
Greetings,
The script below is adapted from one of the wxpython examples. What I wish
to do is when the SQL button is pressed it puts some text retrieved from a
database
field in the "tester" wxTextCtrl along similar lines as the "button" does
with the
"logger" wxTextCtrl.
My problem is how do I pass the variable "field1" to the Appendtext
Control. The
best I keep getting is the "field1" variable does not exist in Form1
Any help appreciated. (I have it working under Tkinter so the connection is OK)
Best Regards
Richard
====Script Begins ====>
from wxPython.wx import *
from pyPgSQL import PgSQL
# set some strings
dbname = 'dbname'
dbhost = 'host'
dbuser = 'user'
dbpass = 'password'
class Form1(wxPanel):
def __init__(self, parent, id):
wxPanel.__init__(self, parent, id)
self.quote = wxStaticText(self, -1, "Your quote :",wxPoint(20, 30))
self.logger = wxTextCtrl(self,5, "",wxPoint(20,70),
wxSize(100,200),wxTE_MULTILINE | wxTE_READONLY)
self.tester = wxTextCtrl(self,6, "",wxPoint(150,70),
wxSize(100,200),wxTE_MULTILINE | wxTE_READONLY)
self.button =wxButton(self, 10, "Save", wxPoint(100, 30))
EVT_BUTTON(self, 10, self.OnClick)
self.close =wxButton(self, 11, "Close", wxPoint(180, 30))
EVT_BUTTON(self, 11, self.Close)
self.sql =wxButton(self, 12, "SQL", wxPoint(180, 10))
EVT_BUTTON(self, 12, self.query)
def OnClick(self,event):
self.logger.AppendText(" Click on object with Id %d\n" %event.GetId())
def Close(self,event):
import sys
sys.exit()
def query(self,event):
mydb =
PgSQL.connect(host=dbhost,database=dbname,user=dbuser,password=dbpass)
c = mydb.cursor()
sqlquery = ("Select * from fmna where code = 'USS001'")
c.execute(sqlquery)
for row in c.fetchall():
field1 = row[0]
field2 = row[1]
mydb.close
self.tester.AppendText("Code returned is:" self.field1)
app = wxPySimpleApp()
frame = wxFrame(None, -1, " Testing Form",
pos=wxDefaultPosition, size=(400, 300))
Form1(frame,-1)
frame.Show(1)
app.MainLoop()
=====> End of Script
More information about the Tutor
mailing list