when inserting data to sqlite using button argument 'command'
<p>hello when ever i try to insert data to sqlite there is an error shows up and the button is Disappears from the frame the issue are in this two piece of function <code>def fitcher(insertFun):</code> and <code>def insertFun(self)</code> </p>

<pre><code>from tkinter import *
from tkinter import ttk
import sqlite3

class mainGui(ttk.Frame):
    def __init__(self):
        Frame.__init__(self,background="lightblue")
        self.master.title("Family book library")
        self.pack(expand=1, fill=BOTH)
        toolBar = Frame(self)
        self.buttonPicInsert = PhotoImage(file="insert.png")
        addbook = ttk.Button(toolBar,image = self.buttonPicInsert,command = self.insertFun)
        addbook.pack(side=LEFT)

        self.buttonPicAnalyse = PhotoImage(file="analys.png")
        analysis = ttk.Button(toolBar, image = self.buttonPicAnalyse,command = self.analysFun)
        analysis.pack(side=LEFT)

        self.buttonPicSearch =  PhotoImage(file="search.png")
        search = ttk.Button(toolBar, image = self.buttonPicSearch)
        search.pack(side=LEFT)

        toolBar.pack(side=LEFT)

        menu = Menu(self.master)
        self.master.config(menu=menu)
        file = Menu(menu)
        file.add_command(label="Exit", command=quit)
        menu.add_cascade(label="File", menu=file)

        tree = ttk.Treeview(show="headings", height=32)
        tree["columns"] = ("1", "2", "3", "4", "5", "6", "7" ,"8")

        tree.column("1", width=132)
        tree.column("2", width=302)
        tree.column("3", width=302)
        tree.column("4", width=142)
        tree.column("5", width=123)
        tree.column("6", width=120)
        tree.column("7", width=120)
        tree.column("8", width=120)


        tree.heading("1", text="BookID")
        tree.heading("2", text="BookTitle")
        tree.heading("3", text="BookAuthor")
        tree.heading("4", text="BookPublisher")
        tree.heading("5", text="edition")
        tree.heading("6", text="PublisherDate")
        tree.heading("7", text="familyOwner")
        tree.heading("8", text="Location")

        tree.insert("", 0, text="BookID", values=("1A", "1b"))

        tree.pack(side=TOP)

    def insertFun(self):
        new = Toplevel(pady=20)
        new.title("insert new book")
        new.transient()
        new.geometry("570x370")
        new.resizable(width=False, height=False)

        # varible text filed #BookTitle label
        new.BookTitle = ttk.Label(new, text="BookTitle ", justify = CENTER)
        new.BookTitle.pack()

        # 1
        new.BookTitleFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.BookTitleFiled.pack()

        # varible text filed #BookAuthor label
        new.BookAuthor = ttk.Label(new, text="BookAuthor ", justify = CENTER)
        new.BookAuthor.pack()

        # 2
        new.BookAuthorFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.BookAuthorFiled.pack()

        # varible text filed #BookPublisher label
        new.BookPub = ttk.Label(new, text="BookPublisher ", justify = CENTER)
        new.BookPub.pack()

        # 3
        new.BookPubFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.BookPubFiled.pack()

        # varible text filed #Edition label
        new.Edition = ttk.Label(new, text="Edition ", justify = CENTER)
        new.Edition.pack()

        # 4
        new.EditionFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.EditionFiled.pack()

        # varible text filed #PublisherDate label
        new.PublisherDate = ttk.Label(new, text="PublisherDate ", justify = CENTER)
        new.PublisherDate.pack()

        # 5
        new.PublisherDateFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.PublisherDateFiled.pack()

        # varible text filed #Owner label
        new.Owner = ttk.Label(new, text="Family Owner ", justify = CENTER)
        new.Owner.pack()

        # 6
        new.OwnerFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.OwnerFiled.pack()

        # varible text filed #location label
        new.location = ttk.Label(new, text="location ", justify = CENTER)
        new.location.pack()

        # 7
        new.locationFiled = ttk.Entry(new, width=90, justify = CENTER)
        new.locationFiled.pack()


        new.submit = ttk.Button(new, text="insert data", command = new.fitcher)
        new.submit.pack(side=BOTTOM,fill=X,pady=1,padx=10)

    def analysFun(self):
        anal = Toplevel()
        anal.title("Wall of fam")
        anal.transient()
        anal.geometry("320x90+450+300")
        anal.resizable(width=False, height=False)
        anal.nsum = Label(anal, text="NumberOfBook")
        anal.nsum.grid(sticky='nw',row=1, column=0)
        anal.nowner = Label(anal, text="NumberOfOwner")
        anal.nowner.grid(sticky='nw',row=2, column=0)
        anal.nowner = Label(anal, text="OwnerName")
        anal.nowner.grid(sticky='nw', row=3, column=0)
        anal.locations = Label(anal, text="LocationDistribution")
        anal.locations.grid(sticky='nw',row=4, column=0)

    def fitcher(insertFun):
        conn = sqlite3.connect('books.sqlite')
        c = conn.cursor()
        BookTitleValue = insertFun.BookTitleFiled.get()
        BookAuthorValue = insertFun.BookAuthorFiled.get()
        BookPublisherValue = insertFun.BookPubFiled.get()
        editionValue = insertFun.EditionFiled.get()
        PublisherDateValue = insertFun.PublisherDateFiled.get()
        familyOwnerValue = insertFun.OwnerFiled.get()
        LocationValue = insertFun.locationFiled.get()

        c.execute("INSERT INTO library (BookTitle, BookAuthor, BookPublisher, edition, PublisherDate,familyOwner,Location) values (? , ?, ?, ?, ?, ?, ?)",
                    (BookTitleValue, BookAuthorValue, BookPublisherValue, editionValue, PublisherDateValue, familyOwnerValue, LocationValue))



if __name__ == "__main__":
    mainGui().mainloop()
</code></pre>

<p>the error message are down below </p>

<pre><code>    C:\Users\issba\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/issba/Desktop/workstation/familyLibrary/mainGui.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\issba\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
    return self.func(*args)
  File "C:/Users/issba/Desktop/workstation/familyLibrary/mainGui.py", line 121, in insertFun
    new.submit = ttk.Button(new, text="insert data", command = new.fitcher)
AttributeError: 'Toplevel' object has no attribute 'fitcher'

Process finished with exit code 0
</code></pre>

<p>you are missing a lot of things here as far as i see 
first you need this function </p>

<pre><code>new.wait_window()
return (new.varb..etc)
</code></pre>

<p>and you need to add this </p>

<pre><code>new.conn.commit()
new.conn.close()
</code></pre>

<p>this function you have to change the indentation take it out of this function <code>__init__</code></p>

<pre><code>def insertFun():
</code></pre>

<p>you have to use this function to take the data </p>

<pre><code>textvariable = new.locationGet
</code></pre>

<p>for example </p>

<pre><code>new.locationGet = tk.StringVar()
new.locationFiled = ttk.Entry(new, width=90, justify = CENTER,textvariable = new.locationGet)
new.locationFiled.pack()
</code></pre>

<p>also change the commend just read this page it's very into your problem <a href="http://ebanshi.cc/questions/4479874/how-to-get-the-value-from-tkinter-toplevel-in-side-a-0-attribute-function" rel="nofollow">here</a></p>

python sqlite tkinter