Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python35\lib\tkinter\__init__.py", line 1559, in __call__
return self.func(*args)
File "C:/Users/DANNY/PycharmProjects/test/test.py", line 63, in <lambda>
btn_ok.bind('<Button-1>', lambda event: self.insert_data(entry_description, combobox, entry_money))
File "C:/Users/DANNY/PycharmProjects/test/test.py", line 71, in insert_data
(description, costs, total))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
import tkinter as tk from tkinter import ttk import sqlite3 conn = sqlite3.connect('finance.db') c = conn.cursor() c.execute( '''CREATE TABLE IF NOT EXISTS finance (id integer primary key, description text, costs text, total real, date current_timestamp)''') c.execute('''select * from finance''') class Main(tk.Frame): def __init__(self, root): super().__init__(root) self.init_main() def init_main(self): toolbar = tk.Frame(bg='#d7d8e0', bd=2) toolbar.pack(side=tk.TOP, fill=tk.X) self.add_img = tk.PhotoImage(file="add.gif") btn_open_dialog = tk.Button(toolbar, text='Добавить позицию', command=self.open_dialog, bg='#d7d8e0', bd=0, compound=tk.TOP, image=self.add_img) btn_open_dialog.pack(side=tk.LEFT) def open_dialog(self): Child() class Child(tk.Toplevel): def __init__(self): super().__init__(root) self.init_child() def init_child(self): self.title('Добавить доходы/расходы') self.geometry('400x220+400+300') self.resizable(False, False) label_description = tk.Label(self, text='Наименование:') label_description.place(x=50, y=50) label_select = tk.Label(self, text='Статья дохода/расхода:') label_select.place(x=50, y=80) label_sum = tk.Label(self, text='Сумма:') label_sum.place(x=50, y=110) entry_description = ttk.Entry(self) entry_description.place(x=200, y=50) entry_money = ttk.Entry(self) entry_money.place(x=200, y=110) combobox = ttk.Combobox(self, values=[u"Доход", u"Расход"]) combobox.current(0) combobox.place(x=200, y=80) btn_cancel = ttk.Button(self, text='Отмена', command=self.destroy) btn_cancel.place(x=300, y=170) btn_ok = ttk.Button(self, text='OK') btn_ok.place(x=220, y=170) btn_ok.bind('<Button-1>', lambda event: self.insert_data(entry_description, combobox, entry_money)) self.grab_set() self.focus_set() self.wait_window() def insert_data(self, description, costs, total): c.execute('''INSERT INTO finance(description, costs, total) VALUES (?, ?, ?)''', (description, costs, total)) conn.commit() '''conn.close()''' self.destroy() if __name__ == "__main__": root = tk.Tk() app = Main(root) app.pack() root.title("Домашние финансы") root.geometry("650x450+300+200") root.resizable(False, False) root.mainloop()
2. Как правильно организовать роботу с БД.
Данную часть кода стоит ли организовать как отдельную функцию и поместить в основной класс или оставить так как есть?
conn = sqlite3.connect('finance.db') c = conn.cursor() c.execute( '''CREATE TABLE IF NOT EXISTS finance (id integer primary key, description text, costs text, total real, date current_timestamp)''') c.execute('''select * from finance''')