日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

tkinter使用MySQL存数据_我无法从tkinter表单向mysql插入数据

發布時間:2025/3/20 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tkinter使用MySQL存数据_我无法从tkinter表单向mysql插入数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我能很好地連接到我的數據庫,總線,不知怎么的,我把它的書寫部分搞砸了。

這是我的代碼:

from tkinter import *

from tkinter import messagebox

import mysql.connector

from mysql.connector import MySQLConnection, Error

db = mysql.connector.connect(

host="localhost",

user="root",

passwd="oliver1989",

database="pruebas_mysql"

)

def insert_newuser():

cursor = db.cursor()

add_usuario = """INSERT INTO reg_us(nombre, paterno, materno, usuario, contra)"

"VALUES(%s, %s, %s, %s, %s)"""% (new_nombre.get(), new_paterno.get(), new_materno.get(), new_usuario.get(), new_contrase?±a.get())

#data_registro = (new_nombre.get(), new_paterno.get(), new_materno.get(), new_usuario.get(), new_contrase?±a.get())

cursor.execute(add_usuario)

db.commit()

def registro_usuario():

screen1=Toplevel(screen)

screen1.geometry("280x400")

screen1.config(bg="#5EC659")

screen.title("Registro")

global new_nombre

new_nombre=StringVar()

global new_paterno

new_paterno=StringVar()

global new_materno

new_materno=StringVar()

global new_usuario

new_usuario=StringVar()

global new_contrase?±a

new_contrase?±a=StringVar()

global con_contrase?±a

con_contrase?±a=StringVar()

Label(screen1, text="Por favor llena este formulario", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Label(screen1, text="", bg="#5EC659").pack()

Label(screen1, text="Nombre / s", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Entry(screen1, textvariable=new_nombre).pack()

Label(screen1, text="Apellido paterno", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Entry(screen1, textvariable=new_paterno).pack()

Label(screen1, text="Apellido Materno", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Entry(screen1, textvariable=new_materno).pack()

Label(screen1, text="Usuario", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Entry(screen1, textvariable=new_usuario).pack()

Label(screen1, text="Contrase?±a", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Entry(screen1, textvariable=new_contrase?±a).pack()

Label(screen1, text="Confirma la contrase?±a", font=("consolas", 10), bg="#5EC659", fg="white").pack()

Entry(screen1, textvariable=con_contrase?±a).pack()

Label(screen1, text="", bg="#5EC659").pack()

Button(screen1, text=" Registrar", height="1", width="10", font=("consolas", 11), command=insert_newuser).pack()

def check_udb():

print("hola")

def main_screen():

global screen

screen = Tk()

screen.geometry("280x300")

screen.config(bg="#5EC659")

screen.title("Planeaciones 1.0")

global usuario

global contrase?±a

usuario = StringVar()

contrase?±a =StringVar()

Label(text="Bienvenido", font=("consolas", 15), bg="#5EC659", fg="white").pack()

Label(text="", bg="#5EC659").pack()

Label(text="Usuario", bg="#5EC659", fg="white", font=("consolas", 13)).pack()

Entry(screen, textvariable = usuario).pack()

Label(text="Contrase?±a", bg="#5EC659", fg="white", font=("consolas", 13)).pack()

Entry(screen, textvariable = contrase?±a).pack()

Label(text="", bg="#5EC659").pack()

Button(text="Ingresar", height="1", width="8", font=("consolas", 10), fg="#1E1E1E", command=check_udb).pack()

Label(text="??No cuentas con usuario?", bg="#5EC659", fg="white").pack()

Label(text="??Facil!, registra tu nuevo usuario.", bg="#5EC659", fg="white").pack()

Button(text="Registrarse", height="1", width="11", font=("consolas", 10), fg="#1E1E1E", command=registro_usuario).pack()

screen.mainloop()

main_screen()

這是控制臺中出現的錯誤:

“C:\用戶\ICATVER 03\PycharmProjects\pruebas

mysqldb\venv\Scripts\python.exe“”C:/Users/ICATVER

03/PycharmProjects/pruebas mysqldb/index.py“Tkinter中的異常

回調回溯(最近一次調用最后一次):文件“C:\用戶\ictor

03\AppData\Local\Programs\Python\Python37-32\lib\tkinter_uuinit_uu.py“,

1705號線,輸入

呼叫

插入新用戶

mysqldb\venv\lib\site packages\mysql\connector\cursor.py“,第551行,

執行中

self._handle_result(self._connection.cmd_query(stmt))文件“C:\Users\ICATVER 03\PycharmProjects\pruebas

mysqldb\venv\lib\site packages\mysql\connector\connection.py“,行

490,在命令查詢中

result=self._handle_result(self._send_cmd(ServerCmd.QUERY,QUERY))文件“C:\用戶\ICATVER 03\PycharmProjects\pruebas

mysqldb\venv\lib\site packages\mysql\connector\connection.py“,行

395,在處理結果中

SQL語法錯誤;請查看與

MySQL服務器的正確語法版本使用near“

第1行的“值(asdf、asdf、asdf、asdf、asdf)”

總結

以上是生活随笔為你收集整理的tkinter使用MySQL存数据_我无法从tkinter表单向mysql插入数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。