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

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Juego en python que no me funciona
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Juego en python que no me funciona  (Leído 3,479 veces)
MisterPython

Desconectado Desconectado

Mensajes: 1


Ver Perfil
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



En línea

tincopasan


Desconectado Desconectado

Mensajes: 1.286

No es lo mismo conocer el camino que recorrerlo.


Ver Perfil
Re: Juego en python que no me funciona
« Respuesta #1 en: 22 Octubre 2020, 00:52 am »

hola:
        deberías ver como trabajar con clases y tkinter, el código en general es muy feo, pero bueno, más allá de eso probá con:

Código
  1. def click(self,texto):
  2.        #Boton flecha Der
  3.        if texto == 'Der':
  4.            self.xsnk+=1
  5.            self.snake.place(x=self.xsnk,y=self.ysnk)
  6.         #Boton Flecha Izq
  7.        elif texto == 'Izq':
  8.            self.xsnk-=1
  9.            self.snake.place(x=self.xsnk,y=self.ysnk)
  10.  
  11.       #etc.    
  12.  
   

para ver si así hace medianamente lo que esperas que haga.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
no me funciona el juego me pide cd
Juegos y Consolas
chufi 7 3,084 Último mensaje 25 Diciembre 2006, 13:32 pm
por tero_34
[Python] ¿Por qué esto no funciona?
Scripting
randomcito 6 4,593 Último mensaje 8 Mayo 2011, 23:01 pm
por xassiz~
SendKey a un Juego no funciona
Programación Visual Basic
vikingoarg 1 1,728 Último mensaje 25 Octubre 2011, 23:02 pm
por CAR3S?
(Python) If no funciona
Scripting
BigKaz 1 1,488 Último mensaje 14 Noviembre 2016, 23:31 pm
por engel lex
como funciona un juego en pc?
Juegos y Consolas
sagunto1234 3 3,073 Último mensaje 14 Diciembre 2016, 14:23 pm
por MCKSys Argentina
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines