0

I am feeding some data to tKinter GUI window and expecting it to get store in a SQLite database when clicking the submit button and the GUI show the table records in window but its not passing the value to db it seems.

I have almost finish the code but values are not passing.I have pshared the troubled portion of the code for reference.

Here is my code

#Date & Month selection
Month_list = ['Jan','Feb','Mar','April','May','June','Jul','Aug','Sep','Oct','Nov','Dec']
Date_list = list(range(1,32))
year_list = list(range(2019,2031))

dt_mn_yr=StringVar()
Jirano=StringVar()
Time=StringVar()
Remark=StringVar()


def drop_down(list_name,set_name,grow,gcolumn):
    """Function will show drop down selection"""
    c=StringVar()
    droplist=OptionMenu(window,c, *list_name)
    droplist.config(width=5)
    c.set(set_name) 
    droplist.grid(row=grow,column=gcolumn)
    return c


def Database():
    """Connect to DB,Insert & Read the records"""
    d= dt.get()
    m= mn.get()
    y = yr.get()
    Date = str(d)+"-"+str(m)+"-"+str(y)
    jira_no = Jirano.get()
    time_mins = Time.get()
    remark = Remark.get()

    #Result Display window
    display_windows = Label(window,text="" ,font=("Arial Bold", 10))
    display_windows.grid(row=900,column=20)

    try:
        conn = sqlite3.connect("AutomationDB.db")
    except:
        return "DB connection error"
    #Creating table
    conn.execute("CREATE TABLE IF NOT EXISTS TimeTrackerTable (Date TEXT,Jirano TEXT,Time TEXT,Remark TEXT)")
    #Inerting records
    conn.execute("INSERT INTO TimeTrackerTable (Date,Jirano,Time,Remark) VALUES (?,?,?,?)",(Date,jira_no,time_mins,remark))




    conn.commit()

    #Reading the records
    cursor= conn.execute("select * from TimeTrackerTable")

    for i in cursor:
        display_windows.configure(text=i)

    conn.close()


dt=drop_down(Date_list,'Date',400,20)
mn=drop_down(Month_list,'Month',400,21)
yr=drop_down(year_list,'Year',400,22)

#dt_mn_yr = dt+"-"+mn+"-"+yr
#dt_mn_yr = str(dt_mn_yr)

#Input JIRA number
jira_no = Entry(window,width = 15,textvar=Jirano)
jira_no.grid(row=450,column =20 )
jira_no = str(jira_no)


#Input Time
time_mins = Entry(window,width = 15,textvar=Time)
time_mins.grid(row=500,column =20)
time_mins = str(time_mins)

#Input Remark
remark = Entry(window,width = 30,textvar=Remark)
remark.grid(row=550,column =20)
remark = str(remark)


#Submit button
Button(window, text='Submit',width=15,bg='brown',fg='white',COMMAND = Database()).grid(row=750,column=20)

window.mainloop()

Current the out put is coming like this enter image description here

Currenlty I am not using the selection values of display current.My requiredment is to see the database select query result after submit button.Any suggestion ?

Chinmay Nayak
  • 203
  • 5
  • 17
  • 2
    Read [Why is Button parameter “command” executed when declared?](https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared) – Henry Yik Apr 18 '19 at 07:28
  • @HenryYik tested with command = Database but geting error "_tkinter.TclError: unknown option "-COMMAND" – Chinmay Nayak Apr 18 '19 at 09:07
  • 1
    its lower-cased. `command=Database` – Henry Yik Apr 18 '19 at 09:08
  • lowercase was the issue.I using select * from which should display me all the records but its only printing the current record I entered.Any idea why this is happening ? – Chinmay Nayak Apr 19 '19 at 15:01

0 Answers0