-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbtk.py
More file actions
43 lines (31 loc) · 1.08 KB
/
Copy pathdbtk.py
File metadata and controls
43 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from Tkinter import *
import MySQLdb
#import tkmessagebox as tm
from tkMessageBox import *
def put(*args):
e_code = i_code.get()
e_name = i_name.get()
e_price = i_price.get()
db = MySQLdb.connect("localhost","root","root","test" )
cur = db.cursor()
cur.execute("insert into book(book_code, book_name, book_price) values ('"+str(e_code)+"', '"+e_name+"', '"+str(e_price)+"')")
db.commit()
db.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()