from tkinter import Toplevel, Button, Tk, Menu
from tkinter import *
#import sqlite3
import pymysql
import tkinter.ttk as ttk
from view_product_info import*
master = Tk()
conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs")
mycursor=conn.cursor()
def entry_form():
Label(master , text="Name", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=0)
Label(master , text="ArmVer", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=0,column=3)
Label(master , text="Speed", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=2)
Label(master , text="Flash", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=2,column=3)
Label(master , text="RAM", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=4)
Label(master , text="GPIO", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=4,column=3)
Label(master , text="AdvTimer", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=6)
Label(master , text="GPTM", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=6,column=3)
Label(master , text="WDG", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=8)
Label(master , text="RTC", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=9)
Label(master , text="UART", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=10)
Label(master , text="I2C", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=11)
Label(master , text="SPI", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=12)
Label(master , text="USB", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=13)
Label(master , text="ADC", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=14)
Label(master , text="EEPROM", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=15)
Label(master , text="DAC", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=16)
Label(master , text="CAN", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=17)
Label(master , text="SDIO", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=18)
Label(master , text="COMP", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=19)
Label(master , text="AES", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=20)
Label(master , text="TRNG", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=21)
Label(master , text="PACK", font=('arial 12 bold'), justify=LEFT, fg='black').grid(row=22)
e1=Entry(master)
Name=e1.grid(row=0,column=1)
e2=Entry(master)
ArmVer = e2.grid(row=0,column=4)
e3=Entry(master)
Speed = e3.grid(row=2,column=1)
e4=Entry(master)
Flash = e4.grid(row=2,column=4)
e5=Entry(master)
RAM = e5.grid(row=4,column=1)
e6=Entry(master)
Gpio = e6.grid(row=4,column=4)
e7=Entry(master)
AdvTimer = e7.grid(row=6,column=1)
e8=Entry(master)
GPTM = e8.grid(row=6,column=4)
e9=Entry(master)
WDG = e9.grid(row=8,column=1)
e10=Entry(master)
RTC = e10.grid(row=9,column=1)
e11=Entry(master)
UART = e11.grid(row=10,column=1)
e12=Entry(master)
I2C = e12.grid(row=11,column=1)
e13=Entry(master)
SPI = e13.grid(row=12,column=1)
e14=Entry(master)
USB = e14.grid(row=13,column=1)
e15=Entry(master)
ADC = e15.grid(row=14,column=1)
e16=Entry(master)
EEPROM = e16.grid(row=15,column=1)
e17=Entry(master)
DAC = e17.grid(row=16,column=1)
e18=Entry(master)
CAN = e18.grid(row=17,column=1)
e19=Entry(master)
SDIO = e19.grid(row=18,column=1)
e20=Entry(master)
COMP = e20.grid(row=19,column=1)
e21=Entry(master)
AES = e21.grid(row=20,column=1)
e22=Entry(master)
TRNG = e22.grid(row=21,column=1)
e23=Entry(master)
PACK = e23.grid(row=22,column=1)
def create_table():
mycursor.execute("CREATE TABLE `mm321` (id INT AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255),ArmVer VARCHAR(255), Speed VARCHAR(255), Flash VARCHAR(255) , RAM VARCHAR(255) , Gpio VARCHAR(255) , AdvTimer VARCHAR(255), GPTM VARCHAR(255), WDG VARCHAR(255),RTC VARCHAR(255),UART VARCHAR(255),I2C VARCHAR(255),SPI VARCHAR(255),USB VARCHAR(255),ADC VARCHAR(255),EEPROM VARCHAR(255),DAC VARCHAR(255),CAN VARCHAR(255),SDIO VARCHAR(255),COMP VARCHAR(255),AES VARCHAR(255),TRNG VARCHAR(255),PACK VARCHAR(255))")
def display_text():
sql = "INSERT INTO `mm321` (Name, ArmVer,Speed,Flash,RAM,Gpio,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,USB,ADC,EEPROM,DAC,CAN,SDIO,COMP,AES,TRNG,PACK) VALUES (%s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
#print("First Name: %s\nstandard:%s\nsubject:%s" % (e1.get(),e2.get(),e3.get()))
Name=e1.get()
ArmVer=e2.get()
Speed=e3.get()
Flash=e4.get()
RAM=e5.get()
Gpio=e6.get()
AdvTimer=e7.get()
GPTM=e8.get()
WDG=e9.get()
RTC=e10.get()
UART=e11.get()
I2C=e12.get()
SPI=e13.get()
USB=e14.get()
ADC=e15.get()
EEPROM=e16.get()
DAC=e17.get()
CAN=e18.get()
SDIO=e19.get()
COMP=e20.get()
AES=e21.get()
TRNG=e22.get()
PACK=e23.get()
val = (Name, ArmVer, Speed,Flash,RAM,Gpio,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,USB,ADC,EEPROM,DAC,CAN,SDIO,COMP,AES,TRNG,PACK)
mycursor.execute(sql, val)
conn.commit()
print(mycursor.rowcount, "record inserted.")
def Database():
conn = pymysql.connect(host="localhost",user="root",password="",db="sslabs")
cursor = conn.cursor()
#cursor.execute("CREATE TABLE IF NOT EXISTS `mm321` (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT, address TEXT, age TEXT)")
cursor.execute("SELECT * FROM `mm321`")
'''if cursor.fetchone() is None:
cursor.execute("INSERT INTO `mm321` (firstname, lastname, address, age) VALUES('Clea', 'Hela', 'San Francisco', '20')")
cursor.execute("INSERT INTO `mm321` (firstname, lastname, address, age) VALUES('Thor', 'Jackson', 'San Aurora', '25')")
cursor.execute("INSERT INTO `users1` (firstname, lastname, address, age) VALUES('Naruto', 'Uzumaki', 'Konoha', '18')")
cursor.execute("INSERT INTO `users1` (firstname, lastname, address, age) VALUES('San', 'Juan', 'Peninsula', '55')")
cursor.execute("INSERT INTO `users1` (firstname, lastname, address, age) VALUES('Juan', 'Dela Cruz', 'San Juan', '22')")
cursor.execute("INSERT INTO `users1` (firstname, lastname, address, age) VALUES('Pedro', 'Bago', 'Bayan', '30')")
'''
conn.commit()
cursor.execute("SELECT * FROM `mm321` ORDER BY `Name` ASC")
fetch = cursor.fetchall()
for data in fetch:
tree.insert('', 'end', values=(data))
cursor.close()
conn.close()
def Search():
if SEARCH.get() != "":
tree.delete(*tree.get_children())
conn = pymysql.connect(host="localhost",user="root",password="",db="sslabs")
cursor = conn.cursor()
cursor.execute("SELECT * FROM `mm321` WHERE `Name` LIKE ? OR `ArmVer` LIKE ?", ('%'+str(SEARCH.get())+'%', '%'+str(SEARCH.get())+'%'))
fetch = cursor.fetchall()
for data in fetch:
tree.insert('', 'end', values=(data))
cursor.close()
conn.close()
def Reset():
conn = pymysql.connect(host="localhost",user="root",password="",db="sslabs")
cursor = conn.cursor()
tree.delete(*tree.get_children())
cursor.execute("SELECT * FROM `mm321` ORDER BY `ArmVer` ASC")
fetch = cursor.fetchall()
for data in fetch:
tree.insert('', 'end', values=(data))
cursor.close()
conn.close()
#=====================================VARIABLES============================================
SEARCH = StringVar()
#=====================================FRAME================================================
Top = Frame(master, width=500, bd=1, relief=SOLID)
Top.pack(side=TOP)
TopFrame = Frame(master, width=500)
TopFrame.pack(side=TOP)
TopForm= Frame(TopFrame, width=300)
TopForm.pack(side=LEFT, pady=10)
TopMargin = Frame(TopFrame, width=260)
TopMargin.pack(side=LEFT)
MidFrame = Frame(master, width=500)
MidFrame.pack(side=TOP)
#=====================================LABEL WIDGET=========================================
lbl_title = Label(Top, width=500, font=('arial', 18), text="Product Search Table")
lbl_title.pack(side=TOP, fill=X)
#=====================================ENTRY WIDGET=========================================
search = Entry(TopForm, textvariable=SEARCH)
search.pack(side=LEFT)
#=====================================BUTTON WIDGET========================================
btn_search = Button(TopForm, text="Search", bg="#006dcc", command=Search)
btn_search.pack(side=LEFT)
btn_reset = Button(TopForm, text="Reset", command=Reset)
btn_reset.pack(side=LEFT)
#=====================================Table WIDGET=========================================
scrollbarx = Scrollbar(MidFrame, orient=HORIZONTAL)
scrollbary = Scrollbar(MidFrame, orient=VERTICAL)
#Name, ArmVer, Speed,Flash,RAM
tree = ttk.Treeview(MidFrame, columns=("ID", "Name", "ArmVer", "Speed", "Flash","RAM","Gpio","AdvTimer","GPTM","WDG","RTC","UART","I2C","SPI","USB","ADC","EEPROM","DAC","CAN","SDIO","COMP","AES","TRNG","PACK"), selectmode="extended", height=400, yscrollcommand=scrollbary.set, xscrollcommand=scrollbarx.set)
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM, fill=X)
tree.heading('ID', text="ID",anchor=W)
tree.heading('Name', text="Name",anchor=W)#1
tree.heading('ArmVer', text="ArmVer",anchor=W)#2
tree.heading('Speed', text="Speed",anchor=W)#3
tree.heading('Flash', text="Flash",anchor=W)#4
tree.heading('RAM', text="RAM",anchor=W)#5
tree.heading('Gpio', text="Gpio",anchor=W)#6
tree.heading('AdvTimer', text="AdvTimer",anchor=W)#7
tree.heading('GPTM', text="GPTM",anchor=W)#8
tree.heading('WDG', text="WDG",anchor=W)#9
tree.heading('RTC', text="RTC",anchor=W)#10
tree.heading('UART', text="UART",anchor=W)#11
tree.heading('I2C', text="I2C",anchor=W)#12#"SPI","USB","ADC","EEPROM","DAC","CAN","SDIO","COMP","AES","TRNG","PACK"
tree.heading('USB', text="USB",anchor=W)#13
tree.heading('ADC', text="ADC",anchor=W)#14
tree.heading('EEPROM', text="EEPROM",anchor=W)#15
tree.heading('DAC', text="DAC",anchor=W)#16
tree.heading('CAN', text="CAN",anchor=W)#17
tree.heading('SDIO', text="SDIO",anchor=W)#18
tree.heading('COMP', text="COMP",anchor=W)#19
tree.heading('AES', text="AES",anchor=W)#20
tree.heading('TRNG', text="TRNG",anchor=W)#21
tree.heading('PACK', text="PACK",anchor=W)#22
tree.column('#0', stretch=NO, minwidth=0, width=0)#1
tree.column('#1', stretch=NO, minwidth=0, width=0)#2
tree.column('#2', stretch=NO, minwidth=0, width=60)#3
tree.column('#3', stretch=NO, minwidth=0, width=60)#4
tree.column('#4', stretch=NO, minwidth=0, width=60)#5
tree.column('#5', stretch=NO, minwidth=0, width=40)#6
tree.column('#6', stretch=NO, minwidth=0, width=40)#7
tree.column('#7', stretch=NO, minwidth=0, width=40)#8
tree.column('#8', stretch=NO, minwidth=0, width=40)#9
tree.column('#9', stretch=NO, minwidth=0, width=40)#10
tree.column('#10', stretch=NO, minwidth=0, width=40)#11
tree.column('#11', stretch=NO, minwidth=0, width=40)#12
tree.column('#12', stretch=NO, minwidth=0, width=40)#13
tree.column('#13', stretch=NO, minwidth=0, width=40)#14
tree.column('#14', stretch=NO, minwidth=0, width=40)#15
tree.column('#15', stretch=NO, minwidth=0, width=40)#16
tree.column('#16', stretch=NO, minwidth=0, width=40)#17
tree.column('#17', stretch=NO, minwidth=0, width=40)#18
tree.column('#18', stretch=NO, minwidth=0, width=40)#19
tree.column('#19', stretch=NO, minwidth=0, width=40)#20
tree.column('#20', stretch=NO, minwidth=0, width=40)#21
tree.column('#21', stretch=NO, minwidth=0, width=40)#22
tree.column('#22', stretch=NO, minwidth=0, width=40)#22
tree.pack()
###########################################################################
menubar = Menu(master)
file = Menu(menubar, tearoff=0)
file.add_command(label="New",command=db_related.display_text)
file.add_command(label="Open")
file.add_command(label="Save")
file.add_command(label="Save as...")
file.add_command(label="Close")
file.add_separator()
file.add_command(label="Exit", command=master.quit)
menubar.add_cascade(label="File", menu=file)
edit = Menu(menubar, tearoff=0)
edit.add_command(label="Undo")
edit.add_separator()
edit.add_command(label="Cut")
edit.add_command(label="Copy")
edit.add_command(label="Paste")
edit.add_command(label="Delete")
edit.add_command(label="Select All")
menubar.add_cascade(label="Edit", menu=edit)
help = Menu(menubar, tearoff=0)
help.add_command(label="About")
menubar.add_cascade(label="Help", menu=help)
view = Menu(menubar, tearoff=0)
view.add_command(label="View")
menubar.add_cascade(label="View", menu=view)
master.config(menu=menubar)
btn=Button(master, text="MM32", fg='blue')
btn.place(x=20, y=40)
btn=Button(master, text="Quectel", fg='blue')
btn.place(x=20, y=80)
btn=Button(master, text="Mornsun", fg='blue')
btn.place(x=20, y=120)
#=====================================INITIALIZATION=======================================
if __name__ == '__main__':
Database()
master.mainloop()
No comments:
Post a Comment