Python Forum
AttributeError: 'int' object has no attribute 'reindex'
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'int' object has no attribute 'reindex'
#1
I got stuck on this error with my code. Basically I am using openpyxl and tkinter to create a program that stores data in an excel file. Every time I complete the entry boxes and press the button I get AttributeError: 'int' object has no attribute 'reindex'. Here is the code
from tkinter import *
from openpyxl import *
from tkinter import messagebox


wb = load_workbook("C:/Users/PC/Desktop/date.xlsx")
sheet = wb.active

def excel():
    sheet.column_dimensions['A']=30
    sheet.column_dimensions['B']=30
    sheet.column_dimensions['C']=10
    sheet.column_dimensions['D']=10
    sheet.cell(row=1, column=1).value="Nume"
    sheet.cell(row=1, column=2).value="Prenume"
    sheet.cell(row=1, column=3).value="Clasa"
    sheet.cell(row=1, column=4).value="Nota"

def focus1(event):
    prenume_e.focus_set()
def focus2(event):
    clasa_e.focus_set()
def focus3(event):
    nota_e.focus_set()
def clear():
    nume_e.delete(0, END)
    prenume_e.delete(0, END)
    clasa_e.delete(0, END)
    nota_e.delete(0, END)

def insert():
    if(nume_e.get()=="" or prenume_e.get()=="" or clasa_e.get()=="" or nota_e.get()==""):
        messagebox.showerror("Eroare", "Va rugam introduceti o valoare")
    else:
        current_row=sheet.max_row
        current_column=sheet.max_column
        sheet.cell(row=current_row + 1, column=1).value=nume_e.get()
        sheet.cell(row=current_row + 1, column=2).value=prenume_e.get()
        sheet.cell(row=current_row + 1, column=3).value=clasa_e.get()
        sheet.cell(row=current_row + 1, column=4).value=nota_e.get()
        wb.save("C:/Users/PC/Desktop/date.xlsx")
        nume_e.focus_set()
        clear()

if __name__ == "__main__":
    root=Tk()
    root.configure(background="light blue")
    root.title("Formular")
    root.geometry("500x300")
    excel()
    formular = Label(root, text="FORMULAR", font="Helvetica 16 bold", bg="light blue", fg="black")
    nume = Label(root, text="Nume: ", font="Helvetica 14 bold", bg="light blue", fg="black")
    prenume = Label(root, text="Prenume: ", font="Helvetica 14 bold", bg="light blue", fg="black")
    clasa = Label(root, text="Clasa: ", font="Helvetica 14 bold", bg="light blue", fg="black")
    nota = Label(root, text="Nota: ", font="Helvetica 14 bold", bg="light blue", fg="black")
    formular.grid(row=0, column=1)
    nume.grid(row=1, column=0)
    prenume.grid(row=2, column=0)
    clasa.grid(row=3, column=0)
    nota.grid(row=4, column=0)
    nume_e = Entry(root)
    prenume_e = Entry(root)
    clasa_e = Entry(root)
    nota_e = Entry(root)
    nume_e.bind("<Return>", focus1)
    prenume_e.bind("<Return>", focus2)
    clasa_e.bind("<Return>", focus3)
    nume_e.grid(row=1, column=1, ipadx="100")
    prenume_e.grid(row=2, column=1, ipadx="100")
    clasa_e.grid(row=3, column=1, ipadx="100")
    nota_e.grid(row=4, column=1, ipadx="100")
    excel()
    confirmare = Button(root, text="CONFIRMARE", fg="red", bg="white", command=insert)
    confirmare.grid(row=5, columnspan=2)
    root.mainloop()
I searched everywhere for this error and I didn't get it solved.
Reply
#2
Please post the full text of the error traceback.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Jan-19-2019, 02:42 PM)ichabod801 Wrote: Please post the full text of the error traceback.

This is the full error
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "D:/Python Projects/untitled1/test.py", line 41, in insert
    wb.save("C:/Users/PC/Desktop/date.xlsx")
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\workbook\workbook.py", line 391, in save
    save_workbook(self, filename)
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\writer\excel.py", line 284, in save_workbook
    writer.save(filename)
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\writer\excel.py", line 266, in save
    self.write_data()
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\writer\excel.py", line 83, in write_data
    self._write_worksheets()
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\writer\excel.py", line 203, in _write_worksheets
    xml = ws._write()
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\worksheet\worksheet.py", line 893, in _write
    return write_worksheet(self)
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\writer\worksheet.py", line 100, in write_worksheet
    cols = ws.column_dimensions.to_tree()
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\worksheet\dimensions.py", line 236, in to_tree
    for col in sorted(self.values(), key=sorter):
  File "D:\Python Projects\untitled1\venv\lib\site-packages\openpyxl\worksheet\dimensions.py", line 229, in sorter
    value.reindex()
AttributeError: 'int' object has no attribute 'reindex'
Reply
#4
I don't know what to tell you. That's pretty deep into the openpyxl code, and the line in your code it's coming from is just an innocuous save. That might be a bug in openpyxl itself.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 757 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,664 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,460 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 739 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,857 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 728 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,315 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,576 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  WebDriver' object has no attribute 'find_element_by_css_selector rickadams 3 5,896 Sep-19-2022, 06:11 PM
Last Post: Larz60+
  'dict_items' object has no attribute 'sort' Calli 6 4,470 Jul-29-2022, 09:19 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020