我回来时遇到了一些麻烦._。
有人能帮助我吗?当我想从Tkinter Entry(Widgets)
向我的数据库添加一些数据时遇到问题。
我在我的数据库中有“book”表,我想把tkinter
的一些数据放到我的表“book”中。
我已经使用get
但我没有得到任何东西在我的程序 有人可以帮助我吗?从Tkinter Python获取数据到数据库MySQL
谢谢。哦,是的,这是我的脚本:)
from tkinter import *
import mysql.connector as mc
import tkinter.messagebox as tm
def put(*args):
e_code = i_code.get()
e_name = i_name.get()
e_price = i_price.get()
conn = mc.connect(user="root", password="mypassword", host="localhost", database="book_test")
cur = conn.cursor()
cur.execute("insert into book(book_code, book_name, book_price) values('"+e_code+"', '"+e_name+"', '"+e_price+"')")
conn.close()
root = Tk()
root.title("GET DATA")
mainframe = Frame(root)
mainframe.pack()
i_code = IntVar()
i_name = StringVar()
i_price = IntVar()
codeEntry = Entry(mainframe, width=7, textvariable=i_code)
nameEntry = Entry(mainframe, width=7, textvariable=i_name)
priceEntry = Entry(mainframe, width=7, textvariable=i_price)
codeEntry.grid(row=0, column=1)
nameEntry.grid(row=1, column=1)
priceEntry.grid(row=2, column=1)
Label(mainframe, text='Book Code').grid(row=0, column=0)
Label(mainframe, text='Book Name').grid(row=1, column=0)
Label(mainframe, text='Book Price').grid(row=2, column=0)
Button(mainframe, text="Insert", command=put).grid(row=3, column=1)
root.mainloop()
我得到这个错误,有人可以帮助我吗?或者给我提供线索hahaha ._。
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__return self.func(*args)
File "/home/oncom/PycharmProjects/guiProject/fkinggetdata.py", line 13, in put
cur.execute("insert into book(book_code, book_name, book_price) values('"+e_code+"', '"+e_name+"', '"+e_price+"')")
TypeError: Can't convert 'int' object to str implicitly
目前尚不清楚你的问题是什么。你有错误信息吗? – scotty3785
等待,我会隐藏尝试和异常..... – Oncom
@ scotty3785老兄你可以查看我编辑的问题以获取更多信息hehehe -_- 谢谢 – Oncom