The code below works. It appears that if the icon is in the first column, it is not interpreted as a icon. I added a row number to your table, and then the icons displayed.
import openpyxl
from kivy.metrics import dp
from kivymd.uix.datatables import MDDataTable
from kivy.uix.anchorlayout import AnchorLayout
from kivymd.app import MDApp
class Example(MDApp):
def build(self):
layout = AnchorLayout()
excelLocation = "answer2.xlsx"
excelWorkbook = openpyxl.load_workbook(excelLocation)
excelSheet = 'Sheet1'
# workSheet = excelWorkbook[excelSheet]
# values = workSheet.values
icons = {'wrong': ("alert-circle", [1, 0, 0, 1], "Wrong"),
'correct': ("checkbox-marked-circle", [39 / 256, 174 / 256, 96 / 256, 1], "Correct")}
values = [[str(i + 1), *row] for i, row in enumerate(excelWorkbook[excelSheet].values)]
for i in range(len(values)):
values[i][1] = icons.get(values[i][1], values[i][1]) # replace correct or wrong with icon tuple
data_tables = MDDataTable(
size_hint=(1, 1),
use_pagination=True,
rows_num=20,
column_data=[
('#', dp(20)), # added a leading row number
("Result", dp(30)),
("Answers", dp(80)),
],
row_data=values
)
layout.add_widget(data_tables)
return layout
Example().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0587be89-c039-4c89-b747-009e52d24499n%40googlegroups.com.
I does not work properly with an icon in the leading column. As a work around I set the width of the first column to 0 and the content to a null string. I believe this works as desired.
import openpyxl
from kivy.metrics import dp
from kivymd.uix.datatables import MDDataTable
from kivy.uix.anchorlayout import AnchorLayout
from kivymd.app import MDApp
class Example(MDApp):
def build(self):
layout = AnchorLayout()
excelLocation = "answer2.xlsx"
excelWorkbook = openpyxl.load_workbook(excelLocation)
excelSheet = 'Sheet1'
# workSheet = excelWorkbook[excelSheet]
# values = workSheet.values
icons = {'wrong': ("alert-circle", [1, 0, 0, 1], "Wrong"),
'correct': ("checkbox-marked-circle", [39 / 256, 174 / 256, 96 / 256, 1], "Correct"
)}
values = [['', *row] for row in excelWorkbook[excelSheet].values]
for i in range(len(values)):
values[i][1] = icons.get(values[i][1], values[i][1]) # replace correct or wrong with icon tuple
data_tables = MDDataTable(
size_hint=(1, 1),
use_pagination=True,
rows_num=20,
column_data=[
('', dp(0)), # added a leading row number
("Result", dp(30)),
("Answers", dp(80)),
],
row_data=values
)
layout.add_widget(data_tables)
return layout
Example().run()
From: Ian Rajkumar
Sent: Tuesday, July 13, 2021 12:04 PM
To: Kivy users support
Subject: Re: [kivy-users] Display Icons in MdDataTable when pulling from excel
Thank you ElliotG, this works amazingly. I would like to remove the column that you added since the number of the question is in the same columns as the icons, only two columns are needed. I am still fairly new to coding, when I try editing the code, it breaks it.
On Tuesday, July 13, 2021 at 2:19:26 PM UTC-3 ElliotG wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/29681b21-d4f6-4cb7-a444-ad535a4f18bdn%40googlegroups.com.
On Jul 13, 2021, at 12:58 PM, Ian Rajkumar <ianra...@gmail.com> wrote:
It had not occurred to me that I could set the column to zero. Great idea. The last thing I would like to accomplish is to bold the text and add a light gray background to the row with the number. This way the student can quickly identify which were the questions. Is that possible?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e6d5be60-dd8c-46f9-9d11-ed5222b06408n%40googlegroups.com.