How to create and populate wx.Grid with data from a database (python / wxpython)

I have been watching the wx demo for many hours and simply cannot wrap this topic around me.

I need to infer information from my database and save its columns and values ​​in a view-only grid (for now)

Can someone please give me an example script of how to do this so that I can implement it with my own data. The grid I need is fixed and fits inside the panel (wx.notebook page). I know how to make this part, but how to get the grid inside the panel and fill it, it confuses me.

Additional information: my database contains information about the client (name, phone, email)

+4
source share
1 answer

If you are looking at a grid demonstration using wx.grid.PyGridTableBase and related ones, you are right: this is really critical code. However, the key method:

def GetValue(self, row, col): return 'something' 

The idea is that if you have data in

 self.data = [[1,2,3,4], [5,6,7,8], ........ ] 

then this will put your data in the appropriate cells:

 def GetValue(self, row, col): return str( self.data[row][column] ) 

( self.data represents your database)

For other simpler examples using wx.grid.Grid with static data or with data for a MySQL database, you can check this and this

Method used to populate a cell with wx.grid.Grid:

 mygrid.SetCellValue(row, col, databasevalue4rowcol) 
+4
source

All Articles