python 我试图使一个污垢,但当使用插入的按钮发生错误

093gszye  于 2024-01-05  发布在  Python
关注(0)|答案(1)|浏览(144)

我尝试做一个crud,但当使用插入的按钮发生错误,每次我尝试添加在crud这发生:

  1. Traceback (most recent call last):
  2. File "C:\Users\mclov\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
  3. return self.func(*args)
  4. File "C:\Users\mclov\pythonProject1\fluxo.py", line 53, in insertdata
  5. inserir(lista)
  6. File "C:\Users\mclov\pythonProject1\lira.py", line 14, in inserir
  7. cursor = conexao.cursor()
  8. File "C:\Users\mclov\abadabado\lib\site-packages\mysql\connector\connection_cext.py", line 706, in cursor
  9. raise OperationalError("MySQL Connection not available.")
  10. mysql.connector.errors.OperationalError: MySQL Connection not available.

字符串
代码:

  1. def insertdata():
  2. tempo = entry_tempo.get()
  3. evento = entry_descrição.get()
  4. debito = entry_entrada.get()
  5. credito = entry_saida.get()
  6. lista = [tempo, evento, debito, credito]
  7. if evento == '' or tempo == '' or credito=='' or debito=='':
  8. messagebox.showerror("campo não pode ser vazio")
  9. else:
  10. inserir(lista)
  11. messagebox.showinfo("todos os dados foram registrados")
  12. entry_tempo.delete(0, "end")
  13. entry_descrição.delete(0, "end")
  14. entry_entrada.delete(0, "end")
  15. entry_saida.delete(0, "end")
  16. for widget in frame_tabela.winfo_children():
  17. widget.destroy()
  18. showitself()

kyks70gy

kyks70gy1#

似乎主要问题是MySQL连接,我建议:

  • 从终端或任何其他工具(如MySQL)测试MySQL连接
  • 检查“inserir”函数,并从那里评估数据插入是否有效
  • 也可以从其他方法中调用代码,例如:连接、CRUD函数等

相关问题