Incorrect number of binding when trying to delete from a database (Tkinter, SQLite)

huangapple go评论97阅读模式
英文:

Incorrect number of binding when trying to delete from a database (Tkinter, SQLite)

问题

以下是您提供的Python代码的翻译部分:

  1. # !/usr/bin/python3
  2. import tkinter as tk
  3. import tkinter.ttk as ttk
  4. from tkinter import messagebox as msg
  5. import sqlite3
  6. class ProyectoPooApp:
  7. # Database connection
  8. database_name = r'database_POO.db'
  9. with sqlite3.connect(database_name) as conn:
  10. cursor = conn.cursor()
  11. update = None
  12. def __init__(self, master=None):
  13. # Build ui
  14. self.win = tk.Tk() if master is None else tk.Toplevel(master)
  15. # Function to center the screen
  16. app_w = 1147
  17. app_h = 379
  18. screen_w = self.win.winfo_screenwidth()
  19. screen_h = self.win.winfo_screenheight()
  20. x = (screen_w / 2) - (app_w / 2)
  21. y = (screen_h / 2) - (app_h / 2)
  22. self.win.geometry(f'{app_w}x{app_h}+{int(x)}+{int(y)}')
  23. self.win.configure(background="#dafcfc")
  24. self.win.iconbitmap("icono.ico")
  25. self.win.resizable(False, False)
  26. self.win.title("Conferencia Arquitectura Hexagonal")
  27. self.frame_data = ttk.Frame(self.win)
  28. # Registration frame
  29. self.frame_registration = tk.LabelFrame(self.frame_data, font=("Helvetica", 13, "bold"))
  30. self.frame_registration.configure(
  31. labelanchor="n",
  32. relief="groove",
  33. text='Inscription')
  34. # Identification label
  35. self.label1 = ttk.Label(self.frame_registration)
  36. self.label1.configure(state="normal", text='Identification')
  37. self.label1.grid(column=0, padx="20 10", pady="20 20", row=0, sticky="e")
  38. # Name label
  39. self.label2 = ttk.Label(self.frame_registration)
  40. self.label2.configure(text='Name\t')
  41. self.label2.grid(column=0, padx="20 10", pady="0 20", row=1, sticky="e")
  42. # Address label
  43. self.label3 = ttk.Label(self.frame_registration)
  44. self.label3.configure(text='Address')
  45. self.label3.grid(column=0, padx="20 10", pady="0 20", row=2, sticky="e")
  46. # Cellphone label
  47. self.label4 = ttk.Label(self.frame_registration)
  48. self.label4.configure(text='Cellphone')
  49. self.label4.grid(column=0, padx="20 10", pady="0 20", row=3, sticky="e")
  50. # Entity label
  51. self.label5 = ttk.Label(self.frame_registration)
  52. self.label5.configure(text='Entity')
  53. self.label5.grid(column=0, padx="20 10", pady="0 20", row=4, sticky="e")
  54. # Date label
  55. self.label6 = ttk.Label(self.frame_registration)
  56. self.label6.configure(text='Date')
  57. self.label6.grid(column=0, padx="20 10", pady="0 20", row=5, sticky="e")
  58. # Entry Identification
  59. self.entry_id = ttk.Entry(self.frame_registration)
  60. self.entry_id.configure(width=33)
  61. self.entry_id.grid(column=1, padx="0 20", pady="20 20", row=0)
  62. # Entry name
  63. self.entry_name = ttk.Entry(self.frame_registration)
  64. self.entry_name.configure(width=33)
  65. self.entry_name.grid(column=1, padx="0 20", pady="0 20", row=1)
  66. # Entry address
  67. self.entry_address = ttk.Entry(self.frame_registration)
  68. self.entry_address.configure(width=33)
  69. self.entry_address.grid(column=1, padx="0 20", pady="0 20", row=2)
  70. # Entry cellphone
  71. self.entry_cellphone = ttk.Entry(self.frame_registration)
  72. self.entry_cellphone.configure(width=33)
  73. self.entry_cellphone.grid(column=1, padx="0 20", pady="0 20", row=3)
  74. # Entry entity
  75. self.entry_entity = ttk.Entry(self.frame_registration)
  76. self.entry_entity.configure(width=33)
  77. self.entry_entity.grid(column=1, padx="0 20", pady="0 20", row=4)
  78. # Entry date
  79. self.entry_date = ttk.Entry(self.frame_registration)
  80. self.entry_date.configure(width=33)
  81. self.entry_date.grid(column=1, padx="0 20", pady="0 20", row=5)
  82. # Button frame
  83. self.frame_registration.grid(column=0, row=0)
  84. self.frame_buttons = ttk.Frame(self.frame_data)
  85. self.frame_buttons.configure(height=200, width=200)
  86. # Save button
  87. self.save_button = ttk.Button(self.frame_buttons)
  88. self.save_button.configure(
  89. cursor="hand2", default="normal", text='Save')
  90. self.save_button.grid(column=0, padx="0 5", row=0)
  91. self.save_button.bind("<1>", self.add_Record, add="+")
  92. # Edit button
  93. self.edit_button = ttk.Button(self.frame_buttons)
  94. self.edit_button.configure(cursor="hand2", text='Edit')
  95. self.edit_button.grid(column=1, padx="5 5", row=0)
  96. self.edit_button.bind("<1>", self.edit_TreeView, add="+")
  97. # Delete button
  98. self.delete_button = ttk.Button(self.frame_buttons)
  99. self.delete_button.configure(cursor="hand2", text='Delete')
  100. self.delete_button.grid(column=2, padx="5 5", row=0)
  101. self.delete_button.bind("<1>", self.delete_Record, add="+")
  102. # Cancel button
  103. self.cancel_button = ttk.Button(self.frame_buttons)
  104. self.cancel_button.configure(cursor="hand2", text='Cancel', command=self.clear_Fields)
  105. self.cancel_button.grid(column=3, padx="5 0", row=0, sticky="e")
  106. self.frame_buttons.grid(column=0, pady="10 0", row=1)
  107. self.frame_data.grid(column=0, pady="30 0", row=0, sticky="n")
  108. # Treeview frame
  109. self.frame_treeview = ttk.Frame(self.win)
  110. # Treeview scrollbar
  111. self.scroll_treeview = ttk.Scrollbar(self.frame_treeview)
  112. self.scroll_treeview.configure(orient="vertical")
  113. self.scroll_treeview.grid(column=1, row=0, sticky="ns")
  114. self.style=ttk.Style()
  115. self.style.configure("style.Treeview", highlightthickness=0, bd=0, background='AliceBlue', fieldbackground="Aliceblue", font=('Helvetica',10))
  116. self.style.configure("style.Treeview.Heading", background='Azure', font=('Helvetica', 10,'bold'))
  117. self.style.map("style.treeview", background = [('selected', "Steelblue")])
  118. self.style.layout("style.Treeview", [('style.Treeview.treearea', {'sticky': 'nswe'})])
  119. # Treeview
  120. self.treeview = ttk.Treeview(self.frame_treeview, yscrollcommand=self.scroll_treeview.set, style="style.Treeview")
  121. self.scroll_treeview.config(command
  122. <details>
  123. <summary>英文:</summary>
  124. I have been doing an interface in Python that can add, edit and delete elements from a database and show said database in a ttk treeview. Right now I&#39;m stuck at the function `elimina_Registro`, which is supposed to delete an item from the database and update the treeview when the `boton_eliminar` button is pressed. When I do press the button to call the function, I get an error message that says `sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 6 supplied.` which is weird because the only binding I&#39;m providing is `self.entry_Id.get()`.
  125. Here&#39;s the complete code:

!/usr/bin/python3

import tkinter as tk
import tkinter.ttk as ttk
from tkinter import messagebox as msg
import sqlite3

class ProyectoPooApp:

  1. #Conexi&#243;n base de datos
  2. nombre_db = r&#39;datebase_POO.db&#39;
  3. with sqlite3.connect(nombre_db) as conn:
  4. cursor = conn.cursor()
  5. actualiza = None
  6. def __init__(self, master=None):
  7. # Build ui
  8. self.win = tk.Tk() if master is None else tk.Toplevel(master)
  9. #Funci&#243;n centrar pantalla
  10. app_w=1147
  11. app_h=379
  12. screen_w = self.win.winfo_screenwidth()
  13. screen_h = self.win.winfo_screenheight()
  14. x= (screen_w/2)-(app_w/2)
  15. y=(screen_h/2)- (app_h/2)
  16. self.win.geometry(f&#39;{app_w}x{app_h}+{int(x)}+{int(y)}&#39;)
  17. self.win.configure(background=&quot;#dafcfc&quot;)
  18. self.win.iconbitmap(&quot;icono.ico&quot;)
  19. self.win.resizable(False, False)
  20. self.win.title(&quot;Conferencia Arquitectura Hexagonal&quot;)
  21. self.frame_datos = ttk.Frame(self.win)
  22. #Frame Iscripci&#243;n
  23. self.frame_inscripcion = tk.LabelFrame(self.frame_datos, font= (&quot;Helvetica&quot;, 13,&quot;bold&quot;))
  24. self.frame_inscripcion
  25. self.frame_inscripcion.configure(
  26. labelanchor=&quot;n&quot;,
  27. relief=&quot;groove&quot;,
  28. text=&#39;Inscripci&#243;n&#39;)
  29. #Label identificacion
  30. self.label1 = ttk.Label(self.frame_inscripcion)
  31. self.label1.configure(state=&quot;normal&quot;, text=&#39;Identificaci&#243;n&#39;)
  32. self.label1.grid(column=0, padx=&quot;20 10&quot;, pady=&quot;20 20&quot;, row=0, sticky=&quot;e&quot;)
  33. #Label nombre
  34. self.label2 = ttk.Label(self.frame_inscripcion)
  35. self.label2.configure(text=&#39;Nombre\t&#39;)
  36. self.label2.grid(column=0, padx=&quot;20 10&quot;, pady=&quot;0 20&quot;, row=1, sticky=&quot;e&quot;)
  37. #Label direccion
  38. self.label3 = ttk.Label(self.frame_inscripcion)
  39. self.label3.configure(text=&#39;Direcci&#243;n&#39;)
  40. self.label3.grid(column=0, padx=&quot;20 10&quot;, pady=&quot;0 20&quot;, row=2, sticky=&quot;e&quot;)
  41. #Label celular
  42. self.label4 = ttk.Label(self.frame_inscripcion)
  43. self.label4.configure(text=&#39;Celular&#39;)
  44. self.label4.grid(column=0, padx=&quot;20 10&quot;, pady=&quot;0 20&quot;, row=3, sticky=&quot;e&quot;)
  45. #Label entidad
  46. self.label5 = ttk.Label(self.frame_inscripcion)
  47. self.label5.configure(text=&#39;Entidad&#39;)
  48. self.label5.grid(column=0, padx=&quot;20 10&quot;, pady=&quot;0 20&quot;, row=4, sticky=&quot;e&quot;)
  49. #Label fecha
  50. self.label6 = ttk.Label(self.frame_inscripcion)
  51. self.label6.configure(text=&#39;Fecha&#39;)
  52. self.label6.grid(column=0, padx=&quot;20 10&quot;, pady=&quot;0 20&quot;, row=5, sticky=&quot;e&quot;)
  53. #Entry Identificacion
  54. self.entry_id = ttk.Entry(self.frame_inscripcion)
  55. self.entry_id.configure(width=33)
  56. self.entry_id.grid(column=1, padx=&quot;0 20&quot;, pady=&quot;20 20&quot;, row=0)
  57. #Entry nombre
  58. self.entry_nombre = ttk.Entry(self.frame_inscripcion)
  59. self.entry_nombre.configure(width=33)
  60. self.entry_nombre.grid(column=1, padx=&quot;0 20&quot;, pady=&quot;0 20&quot;, row=1)
  61. #Entry direcci&#243;n
  62. self.entry_direccion = ttk.Entry(self.frame_inscripcion)
  63. self.entry_direccion.configure(width=33)
  64. self.entry_direccion.grid(column=1, padx=&quot;0 20&quot;, pady=&quot;0 20&quot;, row=2)
  65. #Entry celular
  66. self.entry_celular = ttk.Entry(self.frame_inscripcion)
  67. self.entry_celular.configure(width=33)
  68. self.entry_celular.grid(column=1, padx=&quot;0 20&quot;, pady=&quot;0 20&quot;, row=3)
  69. #Entry entidad
  70. self.entry_entidad = ttk.Entry(self.frame_inscripcion)
  71. self.entry_entidad.configure(width=33)
  72. self.entry_entidad.grid(column=1, padx=&quot;0 20&quot;, pady=&quot;0 20&quot;, row=4)
  73. #Entry fecha
  74. self.entry_fecha = ttk.Entry(self.frame_inscripcion)
  75. self.entry_fecha.configure(width=33)
  76. self.entry_fecha.grid(column=1, padx=&quot;0 20&quot;, pady=&quot;0 20&quot;, row=5)
  77. #Frame botones
  78. self.frame_inscripcion.grid(column=0, row=0)
  79. self.frame_botones = ttk.Frame(self.frame_datos)
  80. self.frame_botones.configure(height=200, width=200)
  81. #Boton grabar
  82. self.boton_grabar = ttk.Button(self.frame_botones)
  83. self.boton_grabar.configure(
  84. cursor=&quot;hand2&quot;, default=&quot;normal&quot;, text=&#39;Grabar&#39;)
  85. self.boton_grabar.grid(column=0, padx=&quot;0 5&quot;, row=0)
  86. self.boton_grabar.bind(&quot;&lt;1&gt;&quot;, self.adiciona_Registro, add=&quot;+&quot;)
  87. #Boton editar
  88. self.boton_editar = ttk.Button(self.frame_botones)
  89. self.boton_editar.configure(cursor=&quot;hand2&quot;, text=&#39;Editar&#39;)
  90. self.boton_editar.grid(column=1, padx=&quot;5 5&quot;, row=0)
  91. self.boton_editar.bind(&quot;&lt;1&gt;&quot;, self.edita_tablaTreeView, add=&quot;+&quot;)
  92. #Boton eliminar
  93. self.boton_eliminar = ttk.Button(self.frame_botones)
  94. self.boton_eliminar.configure(cursor=&quot;hand2&quot;, text=&#39;Eliminar&#39;)
  95. self.boton_eliminar.grid(column=2, padx=&quot;5 5&quot;, row=0)
  96. self.boton_eliminar.bind(&quot;&lt;1&gt;&quot;, self.elimina_Registro, add=&quot;+&quot;)
  97. #Boton cancelar
  98. self.boton_cancelar = ttk.Button(self.frame_botones)
  99. self.boton_cancelar.configure(cursor=&quot;hand2&quot;, text=&#39;Cancelar&#39;, command= self.limpia_Campos)
  100. self.boton_cancelar.grid(column=3, padx=&quot;5 0&quot;, row=0, sticky=&quot;e&quot;)
  101. self.frame_botones.grid(column=0, pady=&quot;10 0&quot;, row=1)
  102. self.frame_datos.grid(column=0, pady=&quot;30 0&quot;, row=0, sticky=&quot;n&quot;)
  103. #Frame treeview
  104. self.frame_treeview = ttk.Frame(self.win)
  105. #Scrollbar treeview
  106. self.scroll_treeview = ttk.Scrollbar(self.frame_treeview)
  107. self.scroll_treeview.configure(orient=&quot;vertical&quot;)
  108. self.scroll_treeview.grid(column=1, row=0, sticky=&quot;ns&quot;)
  109. self.style=ttk.Style()
  110. self.style.configure(&quot;estilo.Treeview&quot;, highlightthickness=0, bd=0, background=&#39;AliceBlue&#39;, fieldbackground=&quot;Aliceblue&quot;, font=(&#39;Helvetica&#39;,10))
  111. self.style.configure(&quot;estilo.Treeview.Heading&quot;, background=&#39;Azure&#39;, font=(&#39;Helvetica&#39;, 10,&#39;bold&#39;))
  112. self.style.map(&quot;estilo.treeview&quot;, background =[(&#39;selected&#39;, &quot;Steelblue&quot;)])
  113. self.style.layout(&quot;estilo.Treeview&quot;, [(&#39;estilo.Treeview.treearea&#39;, {&#39;sticky&#39;: &#39;nswe&#39;})])
  114. #Treeview
  115. self.treeview = ttk.Treeview(self.frame_treeview, yscrollcommand=self.scroll_treeview.set, style = &quot;estilo.Treeview&quot;)
  116. self.scroll_treeview.config(command=self.treeview.yview)
  117. self.treeview.bind(&#39;&lt;Double-Button-1&gt;&#39;, self.edita_tablaTreeView, add=&quot;+&quot;)
  118. self.treeview.configure(
  119. height=15,
  120. selectmode=&quot;browse&quot;,
  121. show=&quot;headings&quot;)
  122. self.treeview_cols = [
  123. &#39;columna_id&#39;,
  124. &#39;columna_nombre&#39;,
  125. &#39;columna_direccion&#39;,
  126. &#39;columna_celular&#39;,
  127. &#39;columna_entidad&#39;,
  128. &#39;columna_fecha&#39;]
  129. self.treeview_dcols = [
  130. &#39;columna_id&#39;,
  131. &#39;columna_nombre&#39;,
  132. &#39;columna_direccion&#39;,
  133. &#39;columna_celular&#39;,
  134. &#39;columna_entidad&#39;,
  135. &#39;columna_fecha&#39;]
  136. self.treeview.configure(
  137. columns=self.treeview_cols,
  138. displaycolumns=self.treeview_dcols)
  139. #Columna id
  140. self.treeview.column(
  141. &quot;columna_id&quot;,
  142. anchor=&quot;w&quot;,
  143. stretch=&quot;true&quot;,
  144. width=120,
  145. minwidth=20)
  146. #Columna nombre
  147. self.treeview.column(
  148. &quot;columna_nombre&quot;,
  149. anchor=&quot;w&quot;,
  150. stretch=&quot;true&quot;,
  151. width=120,
  152. minwidth=20)
  153. #Columna direccion
  154. self.treeview.column(
  155. &quot;columna_direccion&quot;,
  156. anchor=&quot;w&quot;,
  157. stretch=&quot;true&quot;,
  158. width=120,
  159. minwidth=20)
  160. #Columna celular
  161. self.treeview.column(
  162. &quot;columna_celular&quot;,
  163. anchor=&quot;w&quot;,
  164. stretch=&quot;true&quot;,
  165. width=120,
  166. minwidth=20)
  167. #Columna entidad
  168. self.treeview.column(
  169. &quot;columna_entidad&quot;,
  170. anchor=&quot;w&quot;,
  171. stretch=&quot;true&quot;,
  172. width=120,
  173. minwidth=20)
  174. #Columna fecha
  175. self.treeview.column(
  176. &quot;columna_fecha&quot;,
  177. anchor=&quot;w&quot;,
  178. stretch=&quot;true&quot;,
  179. width=120,
  180. minwidth=20)
  181. #Nombres columnas
  182. self.treeview.heading(
  183. &quot;columna_id&quot;,
  184. anchor=&quot;center&quot;,
  185. text=&#39;Id&#39;)
  186. self.treeview.heading(
  187. &quot;columna_nombre&quot;,
  188. anchor=&quot;center&quot;,
  189. text=&#39;Nombre&#39;)
  190. self.treeview.heading(
  191. &quot;columna_direccion&quot;,
  192. anchor=&quot;center&quot;,
  193. text=&#39;Direcci&#243;n&#39;)
  194. self.treeview.heading(
  195. &quot;columna_celular&quot;,
  196. anchor=&quot;center&quot;,
  197. text=&#39;Celular&#39;)
  198. self.treeview.heading(
  199. &quot;columna_entidad&quot;,
  200. anchor=&quot;center&quot;,
  201. text=&#39;Entidad&#39;)
  202. self.treeview.heading(
  203. &quot;columna_fecha&quot;,
  204. anchor=&quot;center&quot;,
  205. text=&#39;Fecha&#39;)
  206. self.treeview.grid(column=0, row=0)
  207. self.frame_treeview.grid(column=1, row=0)
  208. self.win.rowconfigure(0, pad=40)
  209. self.win.columnconfigure(0, pad=40)
  210. self.win.columnconfigure(1, pad=40)
  211. # Main widget
  212. self.mainwindow = self.win
  213. self.lee_tablaTreeView()
  214. def valida(self):
  215. return (len(self.entry_id.get()) != 0 )
  216. def run(self):
  217. self.mainwindow.mainloop()
  218. def valida_Identificacion(self, event=None):
  219. pass
  220. def valida_Fecha(self, event=None):
  221. pass
  222. def carga_Datos(self, values):
  223. self.entry_id.insert(0, values[0])
  224. self.entry_nombre.insert(0, values[1])
  225. self.entry_direccion.insert(0, values[2])
  226. self.entry_celular.insert(0, values[3])
  227. self.entry_entidad.insert(0, values[4])
  228. self.entry_fecha.insert(0, values[5])
  229. def limpia_Campos(self):
  230. self.actualiza = None
  231. self.entry_id.configure(state = tk.NORMAL)
  232. self.entry_id.delete(0, tk.END)
  233. self.entry_nombre.delete(0, tk.END)
  234. self.entry_direccion.delete(0, tk.END)
  235. self.entry_celular.delete(0, tk.END)
  236. self.entry_entidad.delete(0, tk.END)
  237. self.entry_fecha.delete(0, tk.END)
  238. def run_Query(self, query, parametros = ()):
  239. #Funci&#243;n para ejecutar los Querys a la base de datos
  240. result = self.cursor.execute(query, parametros)
  241. self.conn.commit()
  242. return result
  243. def lee_tablaTreeView(self):
  244. self.treeview.delete(*self.treeview.get_children())
  245. query = &#39;SELECT rowid, * FROM Asistentes&#39;
  246. self.run_Query(query)
  247. registros = self.cursor.fetchall()
  248. for record in registros:
  249. self.treeview.insert(parent=&#39;&#39;, index=&#39;end&#39;, iid=record[0], text=&#39;&#39;, values=(record[0], record[2], record[3], record[4], record[5], record[6]))
  250. self.conn.commit()
  251. def adiciona_Registro(self, event=None):
  252. #Adiciona un producto a la base de datos
  253. if self.actualiza:
  254. self.actualiza = None
  255. query = &#39;UPDATE Asistentes SET Id = ?, Nombre = ?, Direcci&#243;n = ?, Celular = ?, Entidad = ?, Fecha = ? WHERE Id = ?&#39;
  256. parametros = (self.entry_id.get(), self.entry_nombre.get(), self.entry_direccion.get(),
  257. self.entry_celular.get(), self.entry_entidad.get(), self.entry_fecha.get(), self.entry_id.get())
  258. self.run_Query(query, parametros)
  259. msg.showinfo(&#39;Ok&#39;,&#39; Registro actualizado con &#233;xito&#39;)
  260. else:
  261. query = &#39;INSERT INTO Asistentes VALUES(?, ?, ?, ?, ?, ?)&#39;
  262. parametros = (self.entry_id.get(), self.entry_nombre.get(), self.entry_direccion.get(),
  263. self.entry_celular.get(), self.entry_entidad.get(), self.entry_fecha.get())
  264. if self.valida():
  265. self.run_Query(query, parametros)
  266. msg.showinfo(&#39;&#39;,f&#39;Registro: {self.entry_id.get()} agregado&#39;)
  267. self.limpia_Campos()
  268. else:
  269. msg.showerror(&quot;&#161;Atenci&#243;n!&quot;,&quot;No puede dejar la identificaci&#243;n vac&#237;a&quot;)
  270. self.limpia_Campos()
  271. self.lee_tablaTreeView()
  272. self.entry_id.configure(state = tk.NORMAL)
  273. def edita_tablaTreeView(self, event=None):
  274. try:
  275. seleccion = self.treeview.focus()
  276. parametros = self.treeview.item(seleccion, &#39;values&#39;)
  277. self.limpia_Campos()
  278. self.actualiza = True # Esta variable controla la actualizaci&#243;n
  279. self.carga_Datos(parametros)
  280. self.entry_id.configure(state = &#39;readonly&#39;)
  281. except IndexError as error:
  282. self.actualiza = None
  283. msg.showerror(&quot;&#161;Atenci&#243;n!&quot;,&#39;Por favor seleccione un &#237;tem de la tabla&#39;)
  284. return
  285. def elimina_Registro(self, event=None):
  286. #Elimina un producto de la base de datos
  287. if self.actualiza:
  288. self.actualiza = None
  289. elemento = self.treeview.selection()[0]
  290. query = &#39;DELETE FROM Asistentes WHERE Id = ?&#39;
  291. parametros = (self.entry_id.get())
  292. opcion = msg.askokcancel(&#39;&#161;Atenci&#243;n!&#39;, &#39;&#191;Borrar registro?&#39;)
  293. if opcion:
  294. self.treeview.delete(elemento)
  295. self.run_Query(query, parametros)
  296. msg.showinfo(&#39;&#39;,f&#39;Registro: {self.entry_id.get()} eliminado&#39;)
  297. else: msg.showinfo(&#39;&#39;, &#39;No se elimin&#243; el registro&#39;)
  298. else:
  299. msg.showerror(&quot;&#161;Atenci&#243;n!&quot;,&quot;Debe seleccionar un registro&quot;)
  300. self.limpia_Campos()
  301. self.lee_tablaTreeView()
  302. self.entry_id.configure(state = tk.NORMAL)

if name == "main":
app = ProyectoPooApp()
app.run()

  1. I was expecting for it to simply delete the item and update the treeview. As the only condition I&#39;m providing is that it has to have the requested Id.
  2. </details>
  3. # 答案1
  4. **得分**: 0
  5. 你在`parametros = (self.entry_id.get())`中缺少了一个逗号,这是因为在Python`("foo") == "foo"`,要创建一个包含一个元素的元组,应该使用`("foo",)`
  6. <details>
  7. <summary>英文:</summary>
  8. You are missing a comma in `parametros = (self.entry_id.get())`, that&#39;s because in Python `(&quot;foo&quot;) == &quot;foo&quot;`, to create a tuple of one element you should use `(&quot;foo&quot;,)`.
  9. </details>

huangapple
  • 本文由 发表于 2023年5月7日 06:32:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191466.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定