from
tkinter
import
*
import
pandas as pd
window
=
Tk()
window.geometry(
"300x200"
)
df
=
pd.read_excel(
"data.xlsx"
)
n_rows
=
df.shape[
0
]
n_cols
=
df.shape[
1
]
column_names
=
df.columns
i
=
0
for
j, col
in
enumerate
(column_names):
text
=
Text(window, width
=
16
, height
=
1
, bg
=
"#9BC2E6"
)
text.grid(row
=
i,column
=
j)
text.insert(INSERT, col)
cells
=
{}
for
i
in
range
(n_rows):
for
j
in
range
(n_cols):
text
=
Text(window, width
=
16
, height
=
1
)
text.grid(row
=
i
+
1
,column
=
j)
text.insert(INSERT, df.loc[i][j])
cells[(i,j)]
=
text
def
do_something():
for
i
in
range
(n_rows):
for
j
in
range
(n_cols):
if
df.loc[i][j] !
=
cells[(i,j)].get(
"1.0"
,
"end-1c"
):
df.loc[[i],column_names[j]]
=
cells[(i,j)].get(
"1.0"
,
"end-1c"
)
df.to_excel(
"new_data.xlsx"
)
save_button
=
Button(
window, height
=
2
,
width
=
16
,
text
=
"Save"
,
command
=
lambda
:do_something())
save_button.grid(row
=
7
,column
=
0
)
window.mainloop()