MATERIAS DEL BLOG

lunes, 21 de mayo de 2018

FORMULARIO PYTHON-MYSQL EN PYTHON 2

       

# -*- coding: utf-8 -*-
from Tkinter import *

#import pymysql
from pymysql import *
import tkMessageBox


def Limpiar():
    rollno.set('')
    nombre.set('')
    edad.set('')
    añostrabajo.set('')
    puesto.set('')
    reputacion.set('')
    salud.set('')
    ID.configure(state='normal')


def buscar():
    try:
        con = pymysql.connect(user='root', password='olmoswilson', \
                              host='localhost', database='libreria')
        cur = con.cursor()
        sql = "Select * from trabajadores where rollno='%s'" % rollno.get()
        cur.execute(sql)
        result = cur.fetchone()
        nombre.set(result[1])
        edad.set(result[2])
        añostrabajo.set(result[3])
        puesto.set(result[4])
        reputacion.set(result[5])
        salud.set(result[6])
        ID.configure(state='disabled')
        con.close()
    except:
        tkMessageBox.showinfo('Sin Datos', 'NO HAY DATOS DISPONIBLES...')
        Limpiar()


def insertar():
    try:
        con = pymysql.connect(user='root', password='olmoswilson', \
                              host='localhost', database='libreria')
        cur = con.cursor()
        sql = "insert into trabajadores values('%s','%s',%s,%s,'%s','%s','%s')" \
              % (rollno.get(), nombre.get(), edad.get(), añostrabajo.get(), puesto.get(), reputacion.get(), salud.get())
        cur.execute(sql)
        con.commit()
        con.close()
        tkMessageBox.showinfo('Exito', 'DATOS INSERTADOS..')
    except:
        tkMessageBox.showinfo('Error', 'Error en los datos...')
    finally:
        Limpiar()


def actualizar():
    try:
        con = pymysql.connect(user='root', password='olmoswilson', \
                              host='localhost', database='libreria')
        cur = con.cursor()
        sql = "update trabajadores set Nombre='%s', Edad=%s, Añostrabajo=%s, Puesto='%s', Reputacion='%s', Salud='%s' where rollno='%s'" \
              % (nombre.get(), edad.get(), añostrabajo.get(), puesto.get(), reputacion.get(), salud.get(), rollno.get())
        cur.execute(sql)
        con.commit()
        con.close()
        tkMessageBox.showinfo('Exito', 'DATOS ACTUALIZADOS..')
    except:
        tkMessageBox.showinfo('Error', 'Error en los datos...')
    finally:
        Limpiar()


def borrar():
    try:
        con = pymysql.connect(user='root', password='olmoswilson', \
                              host='localhost', database='libreria')
        cur = con.cursor()
        sql = "delete from trabajadores where rollno='%s'" \
              % (rollno.get())
        cur.execute(sql)
        con.commit()
        con.close()
        tkMessageBox.showinfo('Exito', 'DATOS BORRADOS..')
    except:
        tkMessageBox.showinfo('Error', 'Error en los datos...')
    finally:
        Limpiar()


ventana = Tk()
ventana.geometry("600x640+350+80")
ventana.title("FORMULARIO LIBRERIA")
ventana.resizable(width=False, height=False)
try:
    ventana.iconbitmap("C:\icono.ico")
except:
    print("no hay icono disponible")

TITULO = Label(ventana, text="FORMULARIO PARA MODIFICAR DATOS A UNA DB ", fg='brown', font=("Courier New", 15))
ETIQUETA1 = Label(ventana, text="ID", font=("Courier New", 15), fg='red')
ETIQUETA2 = Label(ventana, text="NOMBRE", font=("Courier New", 15))
ETIQUETA3 = Label(ventana, text="EDAD", font=("Courier New", 15))
ETIQUETA4 = Label(ventana, text="AÑOS", font=("Courier New", 15))
ETIQUETA5 = Label(ventana, text="PUESTO", font=("Courier New", 15))
ETIQUETA6 = Label(ventana, text="REPUTACION", font=("Courier New", 15))
ETIQUETA7 = Label(ventana, text="SALUD", font=("Courier New", 15))

canvas = Canvas(ventana, width=500, height=500)
img = PhotoImage(file="C:\LOGO2.gif")
canvas.create_image(0, 0, anchor=NW, image=img)

rollno = StringVar()
nombre = StringVar()
edad = StringVar()
añostrabajo = StringVar()
puesto = StringVar()
reputacion = StringVar()
salud = StringVar()

ID = Entry(ventana, width=150, textvariable=rollno, bg='dark turquoise', fg='dark slate gray', font=("Courier New", 15))
NOMBRE = Entry(ventana, width=160, textvariable=nombre, bg='dark turquoise', fg='dark slate gray',
               font=("Courier New", 15))
EDAD = Entry(ventana, width=160, textvariable=edad, bg='dark turquoise', fg='dark slate gray', font=("Courier New", 15))
AÑOSTRABAJO = Entry(ventana, width=160, textvariable=añostrabajo, bg='dark turquoise', fg='dark slate gray',
                    font=("Courier New", 15))
PUESTO = Entry(ventana, width=160, textvariable=puesto, bg='dark turquoise', fg='dark slate gray',
               font=("Courier New", 15))
REPUTACION = Entry(ventana, width=160, textvariable=reputacion, bg='dark turquoise', fg='dark slate gray',
                   font=("Courier New", 15))
SALUD = Entry(ventana, width=160, textvariable=salud, bg='dark turquoise', fg='dark slate gray',
              font=("Courier New", 15))

BUSCAR = Button(ventana, text="BUSCAR", command=buscar, bg='dark slate gray', fg='white',
                activebackground='dodger blue', activeforeground='black', font=("Courier New", 15))
INSERTAR = Button(ventana, text="INSERTAR", command=insertar, bg='dark slate gray', fg='white',
                  activebackground='dodger blue', activeforeground='black', font=("Courier New", 15))
ACTUALIZAR = Button(ventana, text="ACTUALIZAR", command=actualizar, bg='dark slate gray', fg='white',
                    activebackground='dodger blue', activeforeground='black', font=("Courier New", 15))
BORRAR = Button(ventana, text="BORRAR", command=borrar, bg='dark slate gray', fg='white',
                activebackground='dodger blue', activeforeground='black', font=("Courier New", 15))
LIMPIAR = Button(ventana, text="LIMPIAR", command=Limpiar, bg='dark slate gray', fg='white',
                 activebackground='dodger blue', activeforeground='black', font=("Courier New", 15))

TITULO.place(x=20, y=10, width=600, height=30)
ETIQUETA1.place(x=10, y=50, width=150, height=30)
ETIQUETA2.place(x=10, y=100, width=150, height=30)
ETIQUETA3.place(x=10, y=150, width=150, height=30)
ETIQUETA4.place(x=10, y=200, width=150, height=30)
ETIQUETA5.place(x=10, y=250, width=150, height=30)
ETIQUETA6.place(x=10, y=300, width=150, height=30)
ETIQUETA7.place(x=10, y=350, width=150, height=30)

ID.place(x=170, y=50, width=370, height=30)
NOMBRE.place(x=170, y=100, width=370, height=30)
EDAD.place(x=170, y=150, width=370, height=30)
AÑOSTRABAJO.place(x=170, y=200, width=370, height=30)
PUESTO.place(x=170, y=250, width=370, height=30)
REPUTACION.place(x=170, y=300, width=370, height=30)
SALUD.place(x=170, y=350, width=370, height=30)

BUSCAR.place(x=250, y=480, width=130, height=40)
INSERTAR.place(x=30, y=420, width=130, height=40)
ACTUALIZAR.place(x=170, y=420, width=130, height=40)
BORRAR.place(x=310, y=420, width=130, height=40)
LIMPIAR.place(x=450, y=420, width=130, height=40)

ventana.mainloop()

       

No hay comentarios:

Publicar un comentario

FIGURA 3D EN PYTHON

import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1), (1...