import tkinter as tk
import sqlite3 as sql
class main_window:
def __init__(self, window):
self.wind= window
self.wind.geometry('800x500')
self.wind.resizable(0, 0)
self.wind.configure(bg= '#1E1E1E')
self.draw()
def draw(self):
notes_list= tk.Listbox(width= 150, height= 25, bg= '#333333', highlightthickness=0)
notes_list.pack(padx= 10, pady= 5)
open_bt= tk.Button(text= 'Open', width= 8, height= 2, bg= '#B0B0B0')
open_bt.pack(padx= 5, pady= 10, side= 'left')
new_bt= tk.Button(text= 'New', width= 8, height= 2, bg= '#B0B0B0', command= lambda: new_note(tk.Tk()))
new_bt.pack(padx= 5, pady= 10, side= 'left')
delete_bt= tk.Button(text= 'Delete', width= 8, height= 2, bg= '#B0B0B0')
delete_bt.pack(padx= 5, pady= 10, side= 'left')
class new_note:
def __init__(self, window):
self.wind= window
self.wind.geometry('800x450')
self.wind.configure(bg= '#1E1E1E')
self.draw()
def draw(self):
self.title= tk.Entry(self.wind, width= 100, font= ("Comic Sans MS", 10, "bold"), bg= '#333333')
self.title.pack(padx= 10, pady= 3)
self.note= tk.Text(self.wind, width= 100, height= 17, bg= '#333333', font= ("Comic Sans MS", 10, "bold"))
self.note.pack(padx= 10, pady= 5)
save_bt= tk.Button(self.wind, text= 'Save', width= 8, height= 2, bg= '#B0B0B0', command= self.save)
save_bt.pack(padx= 5, pady= 10, side= 'left')
delete_bt= tk.Button(self.wind, text= 'Delete', width= 8, height= 2, bg= '#B0B0B0', command= self.wind.destroy)
delete_bt.pack(padx= 10, pady= 5, side= 'left')
def save(self):
db= sql.connect('notas.db')
curs= db.cursor()
curs.execute("INSERT INTO tb_notes(name, text) VALUES(?, ?)", self.title.get(), self.note.get("1.0",'end-1c'))
db.commit()
db.close()
obj_m_window= main_window(tk.Tk())
obj_m_window.wind.mainloop()
我想将数据保存到表中,但当我按下保存按钮时,我得到此错误TypeError: function takes at most 2 arguments (3 given)
1条答案
按热度按时间6jjcrrmo1#
以元组形式传递数据
cursor.execute()
函数以列表或元组的形式接受两个参数,即SQL语句和数据。更换管路与
请注意,这两个数据:
self.title.get()
和self.note.get("1.0",'end-1c')
现在组合成一个参数。有关
sqlite3
模块的完整说明,请参阅本教程:sqlite3 docs