So I want to run the Tk()
and import there some values. Then these values will be checked from a function that will replacing the value in a particular cell in excel. This cell that matches with one imported entry. My challenge here is that the function works and replacing if I put manually the values inside the program BUT how can I make to read the values from the Tk()
that I enter? I made a button so the function will be running after I have imported the values in the entry fields but still not. The "sntake" and "sngive" in the replace()
function seems to not working... What am I missing?
Code:
from tkinter import *
import pandas as pd
from xlutils.copy import copy
from openpyxl import *
from openpyxl.utils.cell import get_column_letter
import openpyxl
app = Tk()
app.geometry("500x500")
app.title("S/N Management")
heading = Label(text="S/N Management",fg="black",bg="green",width="500",height="3",font="10")
heading.pack()
sngive_text = Label(text="S/N of the delivered ")
sntake_text = Label(text="S/N of the recieved ")
sngive_text.place(x=15,y=80)
sntake_text.place(x=15,y=160)
sngive = StringVar()
sntake = StringVar()
sngive_entry = Entry(textvariable=sngive,width="30")
sntake_entry = Entry(textvariable=sntake,width="30")
sngive_entry.place(x=15,y=100)
sntake_entry.place(x=15,y=180)
def replace():
wb = openpyxl.load_workbook('Tracker.xlsx')
wb.sheetnames
sheet = wb["serials"]
amountOfRows = sheet.max_row
amountOfColumns = sheet.max_column
for i in range(amountOfColumns):
for k in range(amountOfRows):
cell = str(sheet[get_column_letter(i+1)+str(k+1)].value)
if( str(cell) == sntake):
newCell = sngive
sheet[get_column_letter(i+1)+str(k+1)]=newCell
wb.save('tracker_updated.xlsx')
button = Button(app,text="Submit Data",command=replace,width="30",height="2",bg="grey")
button.place(x=140,y=420)
mainloop()