I am imaging fluorescent cells from a 384-well plate and my software spits out a formatted excel analysis of the data (16 rowsx24 columns of images turns into a list of data, with 2 measurements from each well, ~800 data points). Because there is a lot of manual interaction with the data, I want to automate my work by taking the information that's indexed in the excel sheet and map it as a tkinter grid. I want to take my data, have it formatted from a list back to the original 16x24 display. I want to be able to interact with that data, among other things, but as a newbie in python, I'm having a difficult time mapping this data.
I used pandas to read my dataframe, but can't seem to display my list to the appropriate grid box. Ideally, I'd like the values in the excel list to display on the corresponding cell in the tkinter grid. For example, in my excel list, [1]:https://i.sstatic.net/t0Zrm.jpg, the two data points from each well are listed. I want to take the values from each cell and display them to the corresponding grid in tkinter, so the average of values of "A1" would be mapped onto column 1, row 1 of the grid, A2 would be col 2 row 1, A3 would be col 3 row 1, and so on and so forth.
Any help would be great, thank you.
from tkinter import *import pandas as pdfrom pandas import ExcelWriterfrom pandas import ExcelFile
df = pd.read_excel('/Users/Zammam/PycharmProjects/Filipin_Analysis_Zammam/data.xlsx', sheet_name='Dataps')
print(()
class Cell():FILLED_COLOR_BG = "green"EMPTY_COLOR_BG = "white"FILLED_COLOR_BORDER = "green"EMPTY_COLOR_BORDER = "black"def __init__(self, master, x, y, size):self.master = masterself.abs = xself.ord = yself.size= sizeself.fill= Falsedef _switch(self):""" Switch if the cell is filled or not. """self.fill= not self.filldef draw(self):if self.master != None :fill = Cell.FILLED_COLOR_BGoutline = Cell.FILLED_COLOR_BORDERif not self.fill:fill = Cell.EMPTY_COLOR_BGoutline = Cell.EMPTY_COLOR_BORDERxmin = self.abs * self.sizexmax = xmin + self.sizeymin = self.ord * self.sizeymax = ymin + self.sizeself.master.create_rectangle(xmin, ymin, xmax, ymax, fill = fill, outline = outline)class CellGrid(Canvas):def __init__(self,master, rowNumber, columnNumber, cellSize, *args, **kwargs):Canvas.__init__(self, master, width = cellSize * columnNumber , height = cellSize * rowNumber, *args, **kwargs)self.cellSize = cellSizeself.grid = []for row in range(rowNumber):line = []for column in range(columnNumber):line.append(Cell(self, column, row, cellSize))self.grid.append(line)#memorize the cells that have been modified to avoid many switching of state during mouse motion.self.switched = []#bind click actionself.bind("<Button-1>", self.handleMouseClick) #bind moving while clickingself.bind("<B1-Motion>", self.handleMouseMotion)#bind release button action - clear the memory of midified cells.self.bind("<ButtonRelease-1>", lambda event: self.switched.clear())self.draw()def draw(self):for row in self.grid:for cell in row:cell.draw()def create_text(self):for row in self.grid:for cell in row:for i in df:cell.create_text(text = df)def _eventCoords(self, event):row = int(event.y / self.cellSize)column = int(event.x / self.cellSize)return row, columndef handleMouseClick(self, event):row, column = self._eventCoords(event)cell = self.grid[row][column]cell._switch()cell.draw()#add the cell to the list of cell switched during the clickself.switched.append(cell)def handleMouseMotion(self, event):row, column = self._eventCoords(event)cell = self.grid[row][column]if cell not in self.switched:cell._switch()cell.draw()self.switched.append(cell)if __name__ == "__main__" :app = Tk()grid = CellGrid(app, 16, 24, 15)grid.pack()app.mainloop()