elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Temas
Páginas: [1]
1  Programación / Scripting / Juego en python que no me funciona en: 21 Octubre 2020, 10:49 am
Hola buenas estaba haciendo un juego, el cual tiene unos botones, usando la biblioteca tkinter y al ejecutarlo y pulsar alguno de los botones me decia que el programa no me respondia.

El codigo es el siguiente:




import time
import random
from tkinter import Tk, Text, END, Button

class Pantalla:

    def __init__(self):
        self.ventana=Tk()
        self.ventana.title('Snake Game')
        self.ventana.config(bg='OrangeRed')
        self.ventana.config(height=300,width=400)
        self.areajueg=Text (state='disabled',height=10,width=30,background='black',foreground='orange',font=('System',15))
        self.areajueg.grid(row=0,column=0,rowspan=2,pady=5,padx=5)

       
       
        self.areabot=Text(state='disabled',height=5,width=35,background='OrangeRed')
        self.areabot.grid(row=2,column=0,rowspan=2)
       
        self.xsnk=10
        self.ysnk=10
        self.snake=self.crearBoton(':)','No',back='OrangeRed',ancho=1)
        self.snake.place(x=self.xsnk,y=self.ysnk)
       
        food=self.crearBoton(u'\u2620','No',ancho=2,back='silver',fore='Maroon',fuente=('System',15))
        food.place(x=random.randrange(9,251),y=random.randrange(9,171))
       
       
        botonder=self.crearBoton(u'\u2192','Der',ancho=7,alto=2)
        botonizq=self.crearBoton(u'\u2190','Izq',ancho=7,alto=2)
        botonarrb=self.crearBoton(u'\u2191','Arr')
        botonabaj=self.crearBoton(u'\u2193','Abj')
        botonder.place(x=180,y=230)
        botonizq.place(x=20,y=230)
        botonarrb.place(x=105,y=220)
        botonabaj.place(x=105,y=260)
   
       
       
    def crearBoton(self,valor,TFlch,ancho=6,alto=1,back='white',fore='black',fuente=('System',15)):
        return Button(self.ventana,text=valor,width=ancho,height=alto,background=back,foreground=fore,font=fuente,command=lambda:self.click(TFlch))

   

    def click(self,texto):

        #Boton flecha Der
        while texto == 'Der':
            self.xsnk+=1
            self.snake.place(x=self.xsnk,y=self.ysnk)
            time.sleep(1)

            if not texto == 'Der':
                break

        #Boton Flecha Izq
        while texto == 'Izq':
            self.xsnk-=1
            self.snake.place(x=self.xsnk,y=self.ysnk)
            time.sleep(1)

            if not texto == 'Izq':
                break

        #Boton Flecha Arrb
        while texto == 'Arr':
            self.ysnk-=1
            self.snake.place(x=self.xsnk,y=self.ysnk)
            time.sleep(1)
            if not texto == 'Arr':
                break


        while texto == 'Abj':
            self.ysnk+=1
            self.snake.place(x=self.xsnk,y=self.ysnk)
            time.sleep(1)

            if not texto == 'Abj':
                break
           
           
pantalla=Pantalla()





Gracias

Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines