[ MarkoBalkan @ 25.08.2007. 16:44 ] @
import MySQLdb
from Tkinter import *

con = MySQLdb.connect(host="127.0.0.1", port=3306,
user="root", passwd="123", db="a")
cursor = con.cursor( )

sql = "SELECT ID,Ime,Prezime FROM a"
cursor.execute(sql)

results = cursor.fetchall( )
print results

for i in range(5):
for j in range(10):
l = Label(text='%d.%d' % (i,j) , relief=RIDGE)
l.grid(row=i, column=j, sticky=NSEW)

mainloop()

con.close( )



ovo sve radi, ali kako da razdvojim ID,Ime,Prezime i prikazem u gridu?
[ MarkoBalkan @ 12.12.2007. 15:01 ] @
rijeŇ°eno.
[ StefanJer91 @ 12.12.2007. 18:25 ] @
Mogao bi da postavis resenje, cisto ako nekog kasnije bude interesovalo i da uz naziv teme dodas [RESENO]
[ MarkoBalkan @ 12.12.2007. 22:12 ] @
Code:


import MySQLdb
import  wx
import  wx.grid as gridlib



class CustomDataTable(gridlib.PyGridTableBase):
    def __init__(self, log):
        gridlib.PyGridTableBase.__init__(self)
        self.log = log

        self.colLabels = ['ID', 'Description', 'Severity', 'Priority']

       

    db = MySQLdb.Connect(host='localhost', user='root', passwd='123', db="aa")
    cursor = db.cursor()
    cursor.execute("select *   from aa limit 10")
    rows = cursor.fetchall()
    data=rows

   

    def GetNumberRows(self):
        return len(self.data) + 1

    def GetNumberCols(self):
        return len(self.data[0])

    def IsEmptyCell(self, row, col):
        try:
            return not self.data[row][col]
        except IndexError:
            return True


    def GetValue(self, row, col):
        try:
            return self.data[row][col]
        except IndexError:
            return ''

    


    
    def GetColLabelValue(self, col):
        return self.colLabels[col]

   

    
    





#---------------------------------------------------------------------------



class CustTableGrid(gridlib.Grid):
    def __init__(self, parent, log):
        gridlib.Grid.__init__(self, parent, -1)

        table = CustomDataTable(log)

        
        self.SetTable(table, True)

        self.SetRowLabelSize(0)
        self.SetMargins(0,0)
        self.AutoSizeColumns(False)

        gridlib.EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)


  
    def OnLeftDClick(self, evt):
        if self.CanEnableCellControl():
            self.EnableCellEditControl()


#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
    def __init__(self, parent, log):

        wx.Frame.__init__(
            self, parent, -1, "Custom Table, data driven Grid  Demo", size=(640,480)
            )

        p = wx.Panel(self, -1, style=0)
        grid = CustTableGrid(p, log)
        
     
     
      
        bs = wx.BoxSizer(wx.VERTICAL)
        bs.Add(grid, 1, wx.GROW|wx.ALL, 5)
      
        p.SetSizer(bs)

    def OnButton(self, evt):
        print "button selected"

    def OnButtonFocus(self, evt):
        print "button focus"




if __name__ == '__main__':
    import sys
    app = wx.PySimpleApp()
    frame = TestFrame(None, sys.stdout)
    frame.Show(True)
    app.MainLoop()



[ MarkoBalkan @ 12.12.2007. 22:15 ] @
Evo i slike