Entradas

Mostrando entradas de 2019

JUEGO BLACK JACK CON PYGAME

Imagen
Main import casino import pygame import sys import os import math import time import tkinter as tk from tkinter import messagebox pygame.init() cardBack = pygame.image.load(os.path.join('png', 'cardBack.png')) screen = pygame.display.set_mode((1400, 800)) pygame.display.set_caption('Black Jack') clock = pygame.time.Clock() myfont = pygame.font.SysFont('monospace', 70) smallFont = pygame.font.SysFont('monospace', 30) bg = pygame.image.load(os.path.join('back', 'background.jpg')) screen.fill((0,128,0)) clock = pygame.time.Clock() deck = casino.cards() cardList = deck.getCards() d = casino.dealer(cardList) p = casino.player(cardList) pygame.display.flip() onTable = [] topCards = [] cardImg = [None] # Load 52 Images two_clubs = pygame.image.load(os.path.join('png', '2_of_clubs.png')) two_diamonds = pygame.image.load(os.path.join('png', '2_of_diamonds.png')) two_hearts = pygame.image.load(os.p...

Programa imagenes con sonido

Imagen
from Tkinter import * from PIL import Image,ImageTk # la usamos para desplegar las imagenes import os #para poder usar las las ruta de archivos o carpetas import pygame # para reproducir los archivos de sonido mp3 import time import random dir = os.path.dirname(__file__) fotos = dir + '/imagenes2/' sonidos= dir + '/sonidos/' def play(): print "" def stop(): print"" root=Tk() root.geometry('500x500') label = Label(root) label.pack() label2 = Label(root, text="", font=("Arial", 12, "bold")) label2.pack() btn1=Button(root,text="Iniciar",command=play).pack(fill=X) btn2=Button(root,text="Terminar", command=stop).pack(fill=X) arreglo=[1,2,3,4,5,6,7,8] eleccion_aleatoria= str(arreglo.index(random.choice(arreglo))+1) print eleccion_aleatoria figura = fotos + eleccion_aleatoria + '.png' print figura #tomar el nombre del archivo del sonido sonido = sonidos + eleccion_aleator...

mi figura 3d

Imagen
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (0.5, 1, -0.5),#0A (0.5, -1, -0.5),#1B (-0.5, -1, -0.5),#2C (-0.5, 1, -0.5),#3D (0, -0.5, 0.5),#4E (0, 0.5, 0.5),#5F ) edges = ( (0,1), (0,3), (0,5), (2,1), (2,3), (2,4), (4, 5), (4, 1), (4, 2), (5, 4), (5, 0), (5, 3) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (800,600) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) glTranslatef(0.0,0.0, -5) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) ...

Estrella 3d Alfredo

Imagen
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (-2,0,0.75), (-0.75,0,-0.25), (-1.25,0,-2), (0,0,-1), (1.25,0,-2), (0.75,0,-0.25), (2,0,0.75), (0.5,0,0.75), (0,0,2.5), (-0.5,0,0.75), (0,-0.5,0), (0,0.5,0), ) edges = ( (0, 1), (0,9), (0,10), (0,11), (1,10), (1,11), (2,1), (2,3), (2,10), (2,11), (3,10), (3,11), (4, 3), (4,5), (4,10), (4,11), (5,10), (5,11), (6, 5), (6,7), (6,10), (6,11), (7,10), (7,11), (8, 7), (8,9), (8,10), (8,11), (9,10), (9,11) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (1500,1000) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) gluPerspective(45, (display[0]/display[1...

Cubo 3d

Imagen
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1) ) edges = ( (0,1), (0,3), (0,4), (2,1), (2,3), (2,7), (6,3), (6,4), (6,7), (5,1), (5,4), (5,7) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (800,600) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) glTranslatef(0.0,0.0, -5) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) Cube() ...

Thread video

Imagen
import thread import time x=0 def contador(): global x while True: print "Hilo secundario vivo" time.sleep(2) if x==1: break print "Se a acabado la ejecucion del hilo" def main(): global x print "Hilo main iniciado" thread.start_new(contador, ()) x=input("Presione cualquier tecla para terminar") print "Hilo main terminado" main()

Ejemplo Hilos

import threading import time def hola_mundo(nombre): print('hola mundo' + nombre) time.sleep(5) if __name__ =='__main__': hilos= threading.Thread(target=hola_mundo('Angelo')) hilos.start() hilos.join() print ('hola mundo desde el hilo principal')

Cafeteria Ejemplo

Imagen
# -*- coding: utf-8 -*- from Tkinter import * def seleccionar(): cadena = "" if (leche.get()): cadena += "Con leche" else: cadena += "Sin leche" if (azucar.get()): cadena += " y con azúcar" else: cadena += " y sin azúcar" monitor.config(text=cadena) # Configuración de la raíz root = Tk() root.title("Cafetería") root.config(bd=15) leche = IntVar() # 1 si, 0 no azucar = IntVar() # 1 si, 0 no imagen = PhotoImage(file="cafe.gif") Label(root, image=imagen).pack(side="left") frame = Frame(root) frame.pack(side="left") Label(frame, text="¿Cómo quieres el café?").pack(anchor="w") Checkbutton(frame, text="Con leche", variable=leche, onvalue=1, offvalue=0, command=seleccionar).pack(anchor="w") Checkbutton(frame, text="Con azúcar", variable=azucar, onvalue=1, offvalue=...

Interfaz Supermercado Ejemplo

Imagen
from Tkinter import * import Tkinter as tk import tkMessageBox def calcular(): codigo = texto0.get() cantidad = int(texto1.get()) precio = 0 subtotal = 0 articulo = "" suma = 0 if codigo == "a001": articulo = "Banana" precio = 20 subtotal = precio * cantidad suma = suma + subtotal elif codigo == "a002": articulo = "Pasta dental" precio = 25 subtotal = precio * cantidad suma = suma + subtotal elif codigo == "a003": articulo = "cepillo de dientes" precio = 28 subtotal = precio * cantidad suma = suma + subtotal else: tkMessageBox.showerror("Error ", " No se encontro articulo") info = codigo, articulo, cantidad, precio listbox1.insert(0, info) label4 = Label(vp, text=suma) label4.grid(column=2, row=4, padx=(10, 10), pady=(10, 10)) retur...

Conexion con mongoDB

#!/usr/bin/python # -*- coding: utf-8 -*- from Tkinter import * import Tkinter as tk import tkMessageBox global cad, TH, CH, PR, CR, PP, CP, PB, CB, totf, iva, totalP, FP from pymongo import MongoClient def thamb(): hamb = var1.get() cantidad = cant.get() costohamb = 0 if hamb == "Hamburguesa sencilla": costohamb = 15 elif hamb == "Hamburguesa Doble": costohamb = 25 elif hamb == "Hamburguesa triple": costohamb = 35 costo = cantidad * costohamb return costo def comp(): costocomp = 0 cantidadR = cant1.get() cantidadP = cant2.get() cantidadB = cant3.get() refresco = CheckVar1.get() papas = CheckVar2.get() burrito = CheckVar3.get() if refresco == 1: costocomp = costocomp + (15 * cantidadR) if papas == 1: costocomp = costocomp + (20 * cantidadP) if burrito == 1: costocomp = costocomp + (18 * cantidadB) return costocomp def impuesto(...

Interfaz con botón de cancelar

Imagen
# -*- coding: utf-8 -*- from Tkinter import * import Tkinter as tk import tkMessageBox global cad def thamb(): hamb = var1.get() cantidad = cant.get() costohamb = 0 if hamb == "Hamburguesa sencilla": costohamb = 15 elif hamb == "Hamburguesa Doble": costohamb = 25 elif hamb == "Hamburguesa triple": costohamb = 35 costo = cantidad * costohamb return costo def comp(): costocomp = 0 cantidadR = cant1.get() cantidadP = cant2.get() cantidadB = cant3.get() refresco = CheckVar1.get() papas = CheckVar2.get() burrito = CheckVar3.get() if refresco == 1: costocomp = costocomp + (15 * cantidadR) if papas == 1: costocomp = costocomp + (20 * cantidadP) if burrito == 1: costocomp = costocomp + (18 * cantidadB) return costocomp def impuesto(): iva = (0.15 * (thamb() + comp())) return iva def limpiarcajas(): cuadrohamb.delete(0, ...

Interfaz grafica con listbox

Imagen
# -*- coding: utf-8 -*- from Tkinter import * import Tkinter as tk import tkMessageBox global cad def thamb(): hamb = var1.get() cantidad = cant.get() if hamb == "Hamburguesa sencilla": costohamb = 15 elif hamb == "Hamburguesa Doble": costohamb = 25 else: costohamb = 35 costo = cantidad * costohamb return costo def comp(): costocomp = 0 cantidadR = cant1.get() cantidadP = cant2.get() cantidadB = cant3.get() refresco = CheckVar1.get() papas = CheckVar2.get() burrito = CheckVar3.get() if refresco == 1: costocomp = costocomp + (15 * cantidadR) if papas == 1: costocomp = costocomp + (20 * cantidadP) if burrito == 1: costocomp = costocomp + (18 * cantidadB) return costocomp def impuesto(): iva = (0.15 * (thamb() + comp())) return iva def listapedido(): cad = "" hamb = var1.get() refresco = CheckVar1.get() papas...

Usuario y password con TkInter

Imagen
# -*- coding: utf-8 -*- from Tkinter import * import tkMessageBox def usercomp(): cuser = user.get() longitud = len(cuser) notnum = cuser.isalnum() if notnum == False: tkMessageBox.showinfo("Error", "El nombre de usuario puede contener solo letras y números") elif longitud < 6: tkMessageBox.showinfo("Error", "El nombre de usuario debe contener al menos 6 caracteres") elif longitud > 12: tkMessageBox.showinfo("Error", "El nombre de usuario no puede contener más de 12 caracteres") elif longitud > 5 and longitud < 13 and notnum == True: return True def clavecomp(): cpasword = pasword.get() validar = False # que se vayan cumpliendo los requisitos uno a uno. long = len(cpasword) # Calcula la longitud de la contraseña espacio = False # variable para identificar espacios mayuscula = False # variable para identificar letras mayúsculas ...

Interfaz con Tkinter #2

Imagen
# -*- coding: utf-8 -*- from Tkinter import * import Tkinter as tk raiz = Tk() raiz.title("ventana primaria") raiz.resizable(1, 1) # para permitir agrandar o no el ancho o la altura con el moyuse # raiz.geometry("500x600") raiz.config(bg="orange") raiz.config(bd=15) raiz.config(relief="groove") miFrame = Frame(raiz) miFrame.pack() miFrame.config(bg="yellow") miFrame.config(bd=10) miFrame.config(relief="sunken") miFrame.config(cursor="hand2") # Etiquetas miLabel1 = Label(miFrame, text="Hamburguesa feliz", fg="red", bg="yellow", font=("Arial Black", 25)).grid(row=0, column=0, pady="4") OrdenH = Label(miFrame, text="Seleccione la hamburguesa", bg=...

Interfaz Con TkInter #1

Imagen
# -*- coding: utf-8 -*- from Tkinter import * raiz=Tk() raiz.title("ventana primaria") raiz.resizable(1,1) #para permitir agrandar o no el ancho o la altura con el moyuse raiz.iconbitmap("descarga.ico") #raiz.geometry("500x600") raiz.config(bg="cyan") raiz.config(bd=15) raiz.config(relief="groove") miFrame=Frame(raiz) miFrame.pack() miFrame.config(bg="pink") miFrame.config(bd=10) miFrame.config(relief="sunken") miFrame.config(cursor="hand2") miLabel1=Label(miFrame, text="Ingrese sus datos", fg="red",bg="pink",font=("Arial",18)).grid(row=0,column=0,pady="4") """Para insertar imagenes en un label es lo suiguiente: miImagen=PhotoImage(file="mouse.gif") Label(miFrame, image=miImagen).grid(row=0,column=1) """ cuadronombre=Entry(miFrame ) cuadronombre.grid(row=1,column=1,pady="1") cuadronombre.config(fg="...

mi figura con pygame

Imagen
# -*- coding: utf-8 -*- import pygame import time pygame.init() running = True window = pygame.display.set_mode((800, 210)) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False carroseria = (139, 130, 0) ventanas = (139, 130, 85) ruedas = (255, 255, 255) carretera = (255, 255, 255) #carroseria pygame.draw.polygon(window, carroseria, [(60, 160), (280, 160), (280, 100), (240, 100), (220, 60), (140, 60), (100, 100), (60, 100)], 0) #ventanas pygame.draw.polygon(window, ventanas, [(120, 100), (230, 100), (210, 70), (150, 70)], 0) # ruedas pygame.draw.ellipse(window,ruedas,[(100, 130), (50, 60)],1 ) pygame.draw.ellipse(window, ruedas, [(200, 130), (50, 60)], 1) #carretera pygame.draw.polygon(window, carretera, [(0, 220), (1280, 220), (1280, 180), (0, 180)], 0) pygame.display.update()

Perrito con pygame

Imagen
# -*- coding: utf-8 -*- import pygame import time pygame.init() running = True window = pygame.display.set_mode( (1150, 1150) ) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False cara=(139, 130, 0) orejas=(139, 130, 85) menton=(255, 78, 0) ojos=(255, 255, 255) nariz=(255, 255, 255) pygame.draw.polygon(window,cara,[(415, 50), (235, 490), (365, 625), (755, 625), (850, 500), (700, 50)],0) # orejas pygame.draw.polygon(window,orejas,[(415, 50), (60, 320), (175, 635)],0) pygame.draw.polygon(window,orejas,[(700, 50), (1045, 320), (896, 635)],0) # menton pygame.draw.polygon(window,menton,[(365, 625), (550, 415), (755, 625)],0) # ojos # nariz pygame.draw.line(window, nariz, (50, 50), (75, 75), 4) pygame.draw.line(window, nariz, (75, 75), (25, 25), 4) pygame.draw.line(window, nariz, (25, 25), (50, 50), 4) #pygame.draw.line(window , nariz, (50, 50), (75, 75), 4) #pygame.d...

Menu de figuras de Polygonos

Imagen
#-*- coding: utf-8 -*- from Tkinter import * import tkColorChooser # libreria para obtener la gama de colores # crecion de la ventana principal v0 = Tk() v0.title('Menu de figuras con polygonos') v0.config(bg='black') # bg para el color de fondo de la ventana v0.geometry('200x400') # tamaño de la ventana # funciones def mostrar(num, nombre): # ventana secundaria v1 = Toplevel(v0) v1.title(nombre) v1.protocol('Wn_DELETE_WINDOW', "onexit") # para cerrar la ventana por medio de la cruz if num == 1: # Alngel Barrios panel = Canvas(v1, width=1200, height=200, bg="gray") panel.pack() # carroseria panel.create_polygon(60, 160, 280, 160, 280, 100, 240, 100, 220, 60, 140, 60, 100, 100, 60, 100, width=1, fill="red", outline="black") # ruedas panel.create_oval(140, 180, 80, 120, width=1, fill="#1a1200", outline...