I am trying to create a class which will define tkinter entry widgets. I want to be able to pass these parameters to the class:
- Frame in which to create the entry widget.
- Text to insert into the entry widget.
- Width of the entry widget.
- Column and row to grid the widget in.
My class contains one method which will delete the inserted text and change the fg to black. However, whenever I try to create class instances, I get this error message:
_cnfmerge: fallback due to: 'int' object is not iterable
AttributeError: 'int' object has no attribute 'items'
I don't know if the problem is with my understanding of classes, or of tkinter, or of both. I tried searching for similar problems/situations, but the best I found was an example code (Best way to structure a tkinter application?) which I'm trying to follow. Here's my code:
from tkinter import *
from tkinter import ttk
root = Tk()
class BookData_Entry():
def __init__(self,root,text,width,column,row,**kwargs):
self.entry = Entry(root,width,fg='gray')
self.entry.insert(0,text)
self.entry.bind('<FocusIn>',self.handle_focus_in)
self.entry.grid(column=column,row=row)
def handle_focus_in(self, _):
self.entry.delete(0,END)
self.entry.config(fg='black')
BookData_Entry(root,'Please enter the book title',30,1,1)
BookData_Entry(root,"Please enter the author's name",30,2,2)
root.mainloop()
Any help is greatly appreciated.