Hello.
I need print cell value in console when I am navigating through the cells, but I don’t know way somme time print correctly and another time not working.
import wx
import wx.grid
class GridWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Grid Window")
self.initialize_components()
def initialize_components(self):
# Crear la grilla
self.grid = wx.grid.Grid(self, wx.ID_ANY)
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.imprimir_celdas, self.grid)
# Definir el tamaño de las etiquetas de fila y columna
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelSize(20)
# Agregar la grilla a la ventana
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.grid, 1, wx.EXPAND)
self.SetSizer(sizer)
# Popula la grilla
self.grid.CreateGrid(5, 3)
self.grid.SetCellValue(0, 0, "Nombre")
self.grid.SetCellValue(0, 1, "Apellidos")
self.grid.SetCellValue(0, 2, "Edad")
self.grid.SetCellValue(1, 0, "Juan")
self.grid.SetCellValue(1, 1, "Perez")
self.grid.SetCellValue(1, 2, "30")
self.grid.SetCellValue(2, 0, "Pedro")
self.grid.SetCellValue(2, 1, "Garcia")
self.grid.SetCellValue(2, 2, "28")
self.grid.SetCellValue(3, 0, "Maria")
self.grid.SetCellValue(3, 1, "Lopez")
self.grid.SetCellValue(3, 2, "31")
self.grid.SetCellValue(4, 0, "Laura")
self.grid.SetCellValue(4, 1, "Gomez")
self.grid.SetCellValue(4, 2, "25")
def imprimir_celdas(self, event):
col = self.grid.GetGridCursorCol()
row = self.grid.GetGridCursorRow()
print(self.grid.GetCellValue(col, row))
if __name__ == '__main__':
app = wx.App()
grid_window = GridWindow()
grid_window.Show()
app.MainLoop()