Saturday, March 7, 2020

MM32 microcontroller insert form in tkinter python insert data into mysql


from tkinter import *
import pymysql

def View_table():
    mycursor.execute("SELECT * FROM MM32")
    row = mycursor.fetchone()   
    while row is not None:
        print(row)
        row = mycursor.fetchone()

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()

#main code start here
class Application:
    def __init__(self, master):
        self.master = master
        # creating the frames in the master
        self.left = Frame(master, width=1024, height=900, bg='steelblue')
        self.left.pack(side=LEFT)

        #self.right = Frame(master, width=400, height=720, bg='steelblue')
        #self.right.pack(side=RIGHT)
       
        # labels for the window
        self.heading = Label(self.left, text="ONYX COMPONENTS & SYSTEMS", font=('arial 35 bold'), fg='black', bg='steelblue')
        self.heading.place(x=100, y=0)
        # patients name
        #PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.PartNo = Label(self.left, text="PartNo", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.PartNo.place(x=0, y=80)

        # ARMVer
        self.ARMVer = Label(self.left, text="ARMVer", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.ARMVer.place(x=520, y=80)

        # MaxSpeed
        self.MaxSpeed = Label(self.left, text="MaxSpeed", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.MaxSpeed.place(x=0, y=120)

        # Flash
        self.Flash = Label(self.left, text="Flash", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.Flash.place(x=520, y=120)
       
        # RAM
        self.RAM = Label(self.left, text="RAM", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.RAM.place(x=0, y=160)

         # AdvTimer
        self.GPIO = Label(self.left, text="GPIO", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.GPIO.place(x=520, y=160)
             
        # AdvTimer
        self.AdvTimer = Label(self.left, text="AdvTimer", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.AdvTimer.place(x=0, y=200)
       
         #GPTM
        self.GPTM = Label(self.left, text="GPTM", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.GPTM.place(x=520, y=200)
       
         #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.WDG = Label(self.left, text="WDG", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.WDG.place(x=0, y=240)
       
        #RTC
        self.RTC = Label(self.left, text="RTC", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.RTC.place(x=520, y=240)
       
        #UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.UART = Label(self.left, text="UART", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.UART.place(x=0, y=280)
       
         #,I2C
        self.I2C = Label(self.left, text="I2C", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.I2C.place(x=520, y=280)
       
         #SPI
        self.SPI = Label(self.left, text="SPI", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.SPI.place(x=0, y=320)
       
        #PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.USB = Label(self.left, text="USB", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.USB.place(x=520, y=320)
       
         #ADC
        self.ADC = Label(self.left, text="ADC", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.ADC.place(x=0, y=360)
       
        #EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.EEPROM = Label(self.left, text="EEPROM", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.EEPROM.place(x=520, y=360)
       
        #DAC
        self.DAC = Label(self.left, text="DAC", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.DAC.place(x=0, y=400)
       
        #CAN,SDIO,COMP,AES,TRNG
        self.CAN = Label(self.left, text="CAN", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.CAN.place(x=520, y=400)
       
        #SDIO,COMP,AES,TRNG
        self.SDIO = Label(self.left, text="SDIO", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.SDIO.place(x=0, y=440)
       
        #SDIO,COMP,AES,TRNG
        self.COMP = Label(self.left, text="COMP", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.COMP.place(x=0, y=480)
       
        #SDIO,COMP,AES,TRNG
        self.AES = Label(self.left, text="AES", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.AES.place(x=520, y=440)

        #SDIO,COMP,AES,TRNG
        self.TRNG = Label(self.left, text="TRNG", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.TRNG.place(x=0, y=520)
       
        #PACK
        self.PACK = Label(self.left, text="PACK", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.PACK.place(x=520, y=480)
        #"""
        # Entries for all labels============================================================
        #
        ################################################################################
        self.PartNo_ent = Entry(self.left, width=30)#1
        self.PartNo_ent.place(x=250, y=80)

        self.ARMVer_ent = Entry(self.left, width=30)
        self.ARMVer_ent.place(x=640, y=80)
   
        self.MaxSpeed_ent = Entry(self.left, width=30)#3
        self.MaxSpeed_ent.place(x=250, y=120)

        self.Flash_ent = Entry(self.left, width=30)
        self.Flash_ent.place(x=640, y=120)

        self.RAM_ent = Entry(self.left, width=30)#5
        self.RAM_ent.place(x=250, y=160)

        self.GPIO_ent = Entry(self.left, width=30)
        self.GPIO_ent.place(x=640, y=160)
       
        self.AdvTimer_ent = Entry(self.left, width=30)#7
        self.AdvTimer_ent.place(x=250, y=200)
       
        self.GPTM_ent = Entry(self.left, width=30)
        self.GPTM_ent.place(x=640, y=200)
       
        self.WDG_ent = Entry(self.left, width=30)#9
        self.WDG_ent.place(x=250, y=240)
       
        self.RTC_ent = Entry(self.left, width=30)
        self.RTC_ent.place(x=640, y=240)
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.UART_ent = Entry(self.left, width=30)
        self.UART_ent.place(x=250, y=280)
       
        self.I2C_ent = Entry(self.left, width=30)
        self.I2C_ent.place(x=640, y=280)
       
        self.SPI_ent = Entry(self.left, width=30)
        self.SPI_ent.place(x=250, y=320)
       
        self.ADC_ent = Entry(self.left, width=30)
        self.ADC_ent.place(x=640, y=320)
       
        self.EEPROM_ent = Entry(self.left, width=30)
        self.EEPROM_ent.place(x=250, y=360)
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.PACK_ent = Entry(self.left, width=30)
        self.PACK_ent.place(x=640, y=360)
       
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.DAC_ent = Entry(self.left, width=30)
        self.DAC_ent.place(x=250, y=400)
       
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.USB_ent = Entry(self.left, width=30)
        self.USB_ent.place(x=640, y=400)
       
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.CAN_ent = Entry(self.left, width=30)
        self.CAN_ent.place(x=250, y=440)
       
        #SDIO
        self.SDIO_ent = Entry(self.left, width=30)
        self.SDIO_ent.place(x=640, y=440)
       
        #COMP
        self.COMP_ent = Entry(self.left, width=30)
        self.COMP_ent.place(x=250, y=480)
       
        #AES
        self.AES_ent = Entry(self.left, width=30)
        self.AES_ent.place(x=640, y=480)
       
        #TRNG
        self.TRNG_ent = Entry(self.left, width=30)
        self.TRNG_ent.place(x=250, y=520)
       
        # button to perform a command
        self.submit = Button(self.left, text="SUBMIT", width=20, height=2, bg='steelblue', command=self.insert_data_into_table)
        self.submit.place(x=350, y=600)
       
    def create_table(self):
    #uart,i2c,spi,adc,eeprom,pack,dac,,usb,can,sdio,comp,aes,trng
        mycursor.execute("CREATE TABLE MM32 (id INT AUTO_INCREMENT PRIMARY KEY, PartNo VARCHAR(255),ARMVer VARCHAR(255), MaxSpeed 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),ADC VARCHAR(255),EEPROM VARCHAR(255),PACK VARCHAR(255),DAC VARCHAR(255),USB VARCHAR(255),CAN VARCHAR(255),SDIO VARCHAR(255),COMP VARCHAR(255),AES VARCHAR(255),TRNG VARCHAR(255) )")
        print("Table created")
   
    def insert_data_into_table(self):
        sql = "INSERT INTO MM32 (PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG) VALUES (%s, %s ,%s,%s, %s ,%s,%s,%s, %s ,%s,%s, %s ,%s,%s,%s,%s,%s,%s, %s ,%s,%s, %s ,%s)"
        PartNo=input("enter mm32 part")
        ARMVer=input("enter your arm_version")
        MaxSpeed=input("enter your MaxSpeed")
        Flash=input("enter your Flash")
        RAM=input("enter your RAM")
        GPIO=input("enter your GPIO")
        AdvTimer=input("enter your AdvTimer")
        GPTM=input("enter your GPTM")
        WDG=input("enter your WDG")
        RTC=input("enter your RTC")
        UART=input("enter your UART")
        I2C=input("enter your I2C")
        SPI=input("enter your SPI")
        ADC=input("enter your ADC")
        EEPROM=input("enter your EEPROM")
        PACK=input("enter your PACK")
        DAC=input("enter your DAC")
        USB=input("enter your USB")
        CAN=input("enter your CAN")
        SDIO=input("enter your SDIO")#COMP,AES,TRNG
        COMP=input("enter your COMP")
        AES=input("enter your AES")
        TRNG=input("enter your TRNG")
        val = (PartNo, ARMVer,MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG)
        mycursor.execute(sql, val)
        print(mycursor.rowcount, "record inserted.")
    #mycursor.execute(sql, val1)
   
   
####################################################################################
#### main program start from here
####
####################################################################################


conn.commit()

# creating the object
root = Tk()
b = Application(root)

print("\n1.create a table")
print("\n2.insert into table")
print("\n3.View  table")
x=int(input("enter your choice:::"))
if x==1:
    create_table()
elif x==3:
    View_table()
   
elif x==2:
    insert_data_into_table()
   
else :
    print("please enter above options only")
   
#b.create_table()
b.insert_data_into_table()

# resolution of the window
root.geometry("1200x720+0+0")

# preventing the resize feature
root.resizable(False, False)

# end the loop
root.mainloop()


output:


No comments:

Post a Comment

python class topic video