diff --git a/Alarma/alarma.py b/Alarma/alarma.py index ae4c232..e15a032 100644 --- a/Alarma/alarma.py +++ b/Alarma/alarma.py @@ -1,3 +1,5 @@ + + # Alarma # @autor: Magno Efren # Youtube: https://www.youtube.com/c/MagnoEfren @@ -5,14 +7,12 @@ from tkinter import messagebox , Label,Tk,ttk from time import strftime from pygame import mixer - ventana = Tk() ventana.config(bg='black') ventana.geometry('500x250') ventana.title('Alarma') ventana.minsize(width=500, height=250) mixer.init() - lista_horas = [] lista_minutos = [] lista_segundos = [] @@ -40,7 +40,6 @@ combobox3 = ttk.Combobox(ventana, values = lista_segundos , style = "TCombobox", justify='center',width='12', font='Arial') combobox3.grid(row=2, column=2, padx =15, pady=5) combobox3.current(0) - style = ttk.Style() style.theme_create('combostyle', parent='alt',settings = {'TCombobox': {'configure': @@ -67,14 +66,11 @@ def obtener_tiempo(): x_hora = combobox1.get() x_minutos = combobox2.get() x_segundos = combobox3.get() - hora = strftime('%H') minutos = strftime('%M') segundos = strftime('%S') - hora_total = (hora + ' : '+ minutos+ ' : '+ segundos) texto_hora.config(text=hora_total, font = ('Radioland', 25)) - hora_alarma = x_hora +' : '+ x_minutos +' : '+ x_segundos alarma['text']= hora_alarma #condicion: @@ -84,10 +80,9 @@ def obtener_tiempo(): mixer.music.load("audio.mp3") mixer.music.play(loops= int(cantidad.get())) messagebox.showinfo(message=hora_alarma, title="Alarma") - texto_hora.after(100, obtener_tiempo) texto_hora = Label(ventana, fg = 'green2', bg='black') texto_hora.grid(columnspan=3, row=0,sticky="nsew", ipadx=5, ipady=20) obtener_tiempo() - ventana.mainloop() + diff --git a/Bloc de Notas/main.py b/Bloc de Notas/main.py index 4d3ce8c..9a95a4f 100644 --- a/Bloc de Notas/main.py +++ b/Bloc de Notas/main.py @@ -8,6 +8,7 @@ from tkinter import messagebox, filedialog, Toplevel, colorchooser from tkinter import font, BooleanVar + class Ventana(Frame): def __init__(self, master): super().__init__( master) diff --git a/Cronometro/cronometro.py b/Cronometro/cronometro.py index b6d86ff..a7daf78 100644 --- a/Cronometro/cronometro.py +++ b/Cronometro/cronometro.py @@ -1,3 +1,4 @@ + # Cronometro # @autor: Magno Efren # Youtube: https://www.youtube.com/c/MagnoEfren diff --git a/Cronometro/cronometro_v2.py b/Cronometro/cronometro_v2.py index e81aa69..295e2a1 100644 --- a/Cronometro/cronometro_v2.py +++ b/Cronometro/cronometro_v2.py @@ -10,8 +10,6 @@ ventana.minsize(width=500, height=250) ventana.columnconfigure([0,1,2],weight=2) -#ventana.columnconfigure(1, weight=2) -#ventana.columnconfigure(2,weight=2) ventana.rowconfigure(0, weight=2) ventana.rowconfigure(1,weight=1) diff --git a/FlappyBird/audio/die.wav b/FlappyBird/audio/die.wav new file mode 100644 index 0000000..9b79fbd Binary files /dev/null and b/FlappyBird/audio/die.wav differ diff --git a/FlappyBird/audio/hit.wav b/FlappyBird/audio/hit.wav new file mode 100644 index 0000000..9d9b77c Binary files /dev/null and b/FlappyBird/audio/hit.wav differ diff --git a/FlappyBird/audio/point.wav b/FlappyBird/audio/point.wav new file mode 100644 index 0000000..9cf19fe Binary files /dev/null and b/FlappyBird/audio/point.wav differ diff --git a/FlappyBird/audio/swoosh.wav b/FlappyBird/audio/swoosh.wav new file mode 100644 index 0000000..bcae63e Binary files /dev/null and b/FlappyBird/audio/swoosh.wav differ diff --git a/FlappyBird/audio/wing.wav b/FlappyBird/audio/wing.wav new file mode 100644 index 0000000..9ae2c67 Binary files /dev/null and b/FlappyBird/audio/wing.wav differ diff --git a/FlappyBird/images/bird.png b/FlappyBird/images/bird.png new file mode 100644 index 0000000..94a31d9 Binary files /dev/null and b/FlappyBird/images/bird.png differ diff --git a/FlappyBird/images/pipe.png b/FlappyBird/images/pipe.png new file mode 100644 index 0000000..27d113f Binary files /dev/null and b/FlappyBird/images/pipe.png differ diff --git a/FlappyBird/images/reiniciar.png b/FlappyBird/images/reiniciar.png new file mode 100644 index 0000000..429b034 Binary files /dev/null and b/FlappyBird/images/reiniciar.png differ diff --git a/FlappyBird/main.py b/FlappyBird/main.py new file mode 100644 index 0000000..bbe16fc --- /dev/null +++ b/FlappyBird/main.py @@ -0,0 +1,127 @@ +from PIL import Image, ImageTk +import tkinter as tk +from pygame import mixer +import random + +mixer.init() +window = tk.Tk() +window.geometry('1000x600') +window.title('Flappy Bird') + +x = 150 +y = 300 +score = 0 +speed = 10 +game_over = False + +img_bird = Image.open('images/bird.png') +img_bird = ImageTk.PhotoImage(img_bird) + +img_pipe_down = Image.open('images/pipe.png') # 104x900 +img_pipe_top = img_pipe_down.rotate(180) + +img_pipe_down = ImageTk.PhotoImage(img_pipe_down) +img_pipe_top = ImageTk.PhotoImage(img_pipe_top) + +img_reset = Image.open('images/reiniciar.png') +img_reset = ImageTk.PhotoImage(img_reset) + +canvas = tk.Canvas(window, highlightthickness=0, bg= '#00bfff') +canvas.place(relwidth = 1, relheight=1) + +text_score = canvas.create_text(50,50, text= '0', fill='white', font=('D3 Egoistism outline', 30)) + +bird = canvas.create_image(x,y, anchor = 'nw', image =img_bird) +pipe_top = canvas.create_image(1200, -550, anchor= 'nw', image = img_pipe_top) +pipe_down = canvas.create_image(1200, 550, anchor= 'nw', image = img_pipe_down) + +mixer.music.load('audio/swoosh.wav') +mixer.music.play(loops= 0) + +def move_bird_key(event): + global x,y + if not game_over: + y -=30 + canvas.coords(bird, x,y) + mixer.music.load('audio/wing.wav') + mixer.music.play(loops= 0) + + +window.bind( "", move_bird_key) + + +def move_bird(): + global x,y + y +=5 + canvas.coords(bird, x,y) + if y<0 or y> window.winfo_height(): + game_end() + + if not game_over: + window.after(50, move_bird) + +def move_pipe(): + global score, game_over, speed + canvas.move(pipe_top, -speed, 0) + canvas.move(pipe_down, -speed, 0) + if canvas.coords(pipe_down)[0] < -100: + score += 1 + speed += 1 + canvas.itemconfigure(text_score, text = str(score)) + h = window.winfo_height() + num = random.choice([i for i in range(160,h, 160)]) + canvas.coords(pipe_down, window.winfo_width(), num+160) + canvas.coords(pipe_top, window.winfo_width(), num-900) + + if 0 < canvas.coords(pipe_down)[0]<160: + channel = mixer.Channel(1) + channel.set_volume(1.0) + sound = mixer.Sound('audio/point.wav') + channel.play(sound, loops= 0) + + if canvas.coords(pipe_down): + if canvas.bbox(bird)[0] < canvas.bbox(pipe_down)[2] and canvas.bbox(bird)[2]> canvas.bbox(pipe_down)[0]: + if canvas.bbox(bird)[1] < canvas.bbox(pipe_top)[3] or canvas.bbox(bird)[3]> canvas.bbox(pipe_down)[1]: + game_end() + if not game_over: + window.after(50, move_pipe) + + +def reset_game(): + global x,y,score, speed, game_over + x = 150 + y = 300 + score = 0 + speed = 10 + game_over = False + canvas.coords(bird, x,y) + canvas.coords(pipe_top, 1200,-550) + canvas.coords(pipe_down, 1200, 550) + canvas.itemconfigure(text_score, text ="0") + lbl_game_over.place_forget() + bt_reset.place_forget() + move_bird() + move_pipe() + mixer.music.load('audio/swoosh.wav') + mixer.music.play(loops= 0) + +def game_end(): + global game_over + game_over = True + lbl_game_over.place(relx =0.5, rely =0.5, anchor='center') + bt_reset.place(relx = 0.5, rely = 0.7, anchor ='center') + mixer.music.load('audio/hit.wav') + mixer.music.play(loops= 0) + while mixer.music.get_busy(): + continue + mixer.music.load('audio/die.wav') + mixer.music.play(loops= 0) + +lbl_game_over = tk.Label(window, text = 'Game Over !', font= ('D3 Egoistism outline', 30), fg='white', bg='#00bfff') +bt_reset = tk.Button(window, border = 0, image= img_reset, activebackground='#00bfff', bg= '#00bfff', command = reset_game) + +window.after(50, move_bird) +window.after(50, move_pipe) + +window.call('wm', 'iconphoto', window._w, img_bird) +window.mainloop() diff --git a/GUI API OpenAI/assets/icon.png b/GUI API OpenAI/assets/icon.png new file mode 100644 index 0000000..36d8030 Binary files /dev/null and b/GUI API OpenAI/assets/icon.png differ diff --git a/GUI API OpenAI/assets/save.png b/GUI API OpenAI/assets/save.png new file mode 100644 index 0000000..6aff5ab Binary files /dev/null and b/GUI API OpenAI/assets/save.png differ diff --git a/GUI API OpenAI/assets/send.png b/GUI API OpenAI/assets/send.png new file mode 100644 index 0000000..510fe9b Binary files /dev/null and b/GUI API OpenAI/assets/send.png differ diff --git a/GUI API OpenAI/main.py b/GUI API OpenAI/main.py new file mode 100644 index 0000000..534c194 --- /dev/null +++ b/GUI API OpenAI/main.py @@ -0,0 +1,91 @@ +# Youtube: Magno Efren + +from tkinter import Tk, Frame, Button,PhotoImage,Label,Text +from tkinter.scrolledtext import ScrolledText +from tkinter import filedialog, messagebox +from customtkinter import CTk, CTkButton +import openai #pip install openai + +openai.api_key ="OPENAI_API_KEY" + +def generate_text(prompt): + try: + response = openai.Completion.create( + model="text-davinci-003", + prompt=prompt, + temperature=0.7, + max_tokens=100, + top_p=1, + frequency_penalty=0, + presence_penalty=0, + ) + return response.choices[0].text + except Exception as e: + return 'No se conecto a la IA' + +def save_file(): + text = text_out.get("1.0", 'end') + file_path = filedialog.asksaveasfilename(defaultextension=".txt") + with open(file_path, "w") as file: + file.write(text) + + +def show_data(): + question = text_in.get('1.0', 'end') + if len(question) != 0: + text_in.delete('1.0', 'end') + question_show = '\n' + 'YO: ' + '\n' + question + text_out.insert('end', question_show) + res = generate_text(question) + res = 'IA: ' + res #'\n' + text_out.insert('end', res) + else: + messagebox.showerror('Error', 'No se logro comunicar') + +window = CTk() +window.geometry('600x400+400+100') +window.title('Aplicación ChatGTP') +window.config(bg='black') +window.minsize(500, 300) +window.iconphoto(False, PhotoImage(file='assets/icon.png')) + +img_save = PhotoImage(file= 'assets/save.png') +img_send = PhotoImage(file= 'assets/send.png') + + +frame_text = Frame(window, bg= 'white', width=400, height=400) +frame_text.grid(column=0, row=0, sticky='nsew', pady = 5, padx=5) +frame_control = Frame(window, bg= 'black', width=200, height=400) +frame_control.grid(column=1, row=0, sticky='nsew', pady = 5, padx=5) + +window.columnconfigure(0, weight=6) +window.columnconfigure(1, weight=1) +window.rowconfigure(0, weight=1) + +frame_text.grid_propagate(0) +frame_control.grid_propagate(0) + +frame_text.columnconfigure(0, weight=1) +frame_text.rowconfigure(0, weight=1) + +frame_control.columnconfigure(0, weight=1) +frame_control.rowconfigure([0,1,2], weight=1) + +text_out = ScrolledText(frame_text, font = ('Arial', 12), insertbackground= 'blue', + bg= 'black', fg= 'white') +text_out.grid(column=0, row=0, sticky= 'nsew') + +text_in = Text(frame_control, font = ('Arial', 12), insertbackground= 'blue', + bg= 'black', fg= 'white', height=12) +text_in.grid(column=0, row=0) + +button_send = CTkButton(frame_control,image = img_send,compound= 'left',text= ' ENVIAR', + text_font= ('Arial', 11, 'bold') , fg_color= 'blue', command= show_data) +button_send.grid(column = 0, row=1, sticky='nsew',pady = 15, padx=15) + +button_save = CTkButton(frame_control,image = img_save,compound= 'left',text= 'GUARDAR', + text_font= ('Arial', 11, 'bold') , fg_color= 'blue', command= save_file) +button_save.grid(column = 0, row=2, sticky='nsew',pady = 15, padx=15) + + +window.mainloop() \ No newline at end of file diff --git a/Juego Snake/Snake.py b/Juego Snake/Snake.py index b409b3e..7637e79 100644 --- a/Juego Snake/Snake.py +++ b/Juego Snake/Snake.py @@ -6,7 +6,6 @@ from tkinter import Tk, Frame, Canvas, Button,Label, IntVar, ALL import random from pygame import mixer - x, y =15,15 direction = '' posicion_x = 15 diff --git a/README.md b/README.md index 7cf7465..741cb86 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Entre estas y muchas mas aplicaciones realizas con Tkinter en Python encontrara ### Login (Inicio de sesión) en Python con Tkinter - Validación de datos MySQL -![1](https://github.com/MagnoEfren/gui_python_tkinter/blob/main/Login/login-tkinter.png) +![1](https://github.com/MagnoEfren/gui_python_tkinter/blob/main/Login/login-tkinter.png ) @@ -31,14 +31,17 @@ Entre estas y muchas mas aplicaciones realizas con Tkinter en Python encontrara - +
-#### Si desea apoyar puede hacerlo aquí: -#### Nunca es obligatorio, pero se agradece mucho. 😊 +#### ___Si desea apoyar puede hacerlo aquí:___ +#### ___Nunca es obligatorio, pero se agradece mucho.___ 😊 + + +
diff --git a/Snake_v2/assets/audio_snake.mp3 b/Snake_v2/assets/audio_snake.mp3 new file mode 100644 index 0000000..87028aa Binary files /dev/null and b/Snake_v2/assets/audio_snake.mp3 differ diff --git a/Snake_v2/main.py b/Snake_v2/main.py new file mode 100644 index 0000000..a83f55f --- /dev/null +++ b/Snake_v2/main.py @@ -0,0 +1,360 @@ +# Juego Snake V2 +# @autor: Magno Efren (Optimizado) +# Youtube: https://www.youtube.com/c/MagnoEfren + +from tkinter import Tk, Frame, Canvas, Button, Label, ALL +import random +from pygame import mixer + +class SnakeGame: + def __init__(self, ventana): + self.ventana = ventana + self.configurar_ventana() + + # Variables del juego + self.x = 15 + self.y = 15 + self.direction = '' + self.posicion_snake = [(75, 75)] + self.posicion_food = (15, 15) + self.juego_activo = False + self.juego_pausado = False + self.velocidad = 300 + self.posiciones_validas = [15, 45, 75, 105, 135, 165, 195, 225, 255, + 285, 315, 345, 375, 405, 435, 465] + + # Inicializar mixer + try: + mixer.init() + except: + pass + + # Crear interfaz + self.crear_interfaz() + self.crear_tablero() + + def configurar_ventana(self): + """Configura la ventana principal""" + self.ventana.config(bg='black') + self.ventana.title('Juego Snake - Mejorado') + self.ventana.geometry('485x569') + self.ventana.resizable(0, 0) + + def crear_interfaz(self): + """Crea los frames y controles del juego""" + # Frame superior (controles) + self.frame_controles = Frame(self.ventana, width=485, height=60, bg='black') + self.frame_controles.grid(column=0, row=0, pady=5) + + # Frame del juego + self.frame_juego = Frame(self.ventana, width=485, height=490, bg='black') + self.frame_juego.grid(column=0, row=1) + + # Botones de control + self.btn_iniciar = Button( + self.frame_controles, + text='▶ INICIAR', + bg='lime green', + fg='white', + font=('Arial', 10, 'bold'), + width=10, + command=self.iniciar_juego + ) + self.btn_iniciar.grid(row=0, column=0, padx=5, pady=5) + + self.btn_pausar = Button( + self.frame_controles, + text='⏸ PAUSAR', + bg='yellow', + fg='black', + font=('Arial', 10, 'bold'), + width=10, + command=self.pausar_juego, + state='disabled' + ) + self.btn_pausar.grid(row=0, column=1, padx=5, pady=5) + + self.btn_reset = Button( + self.frame_controles, + text='🔄 RESET', + bg='orange', + fg='white', + font=('Arial', 10, 'bold'), + width=10, + command=self.resetear_juego + ) + self.btn_reset.grid(row=0, column=2, padx=5, pady=5) + + self.btn_salir = Button( + self.frame_controles, + text='✖ SALIR', + bg='red', + fg='white', + font=('Arial', 10, 'bold'), + width=10, + command=self.salir + ) + self.btn_salir.grid(row=0, column=3, padx=5, pady=5) + + # Label de puntuación + self.lbl_puntuacion = Label( + self.frame_controles, + text='Puntuación 🍎: 1', + bg='black', + fg='lime green', + font=('Arial', 12, 'bold') + ) + self.lbl_puntuacion.grid(row=1, column=0, columnspan=4, pady=5) + + # Canvas del juego + self.canvas = Canvas(self.frame_juego, bg='black', width=479, height=479) + self.canvas.pack() + + # Vincular teclas + self.ventana.bind("", lambda e: self.cambiar_direccion('up')) + self.ventana.bind("", lambda e: self.cambiar_direccion('down')) + self.ventana.bind("", lambda e: self.cambiar_direccion('left')) + self.ventana.bind("", lambda e: self.cambiar_direccion('right')) + self.ventana.bind("", lambda e: self.pausar_juego()) + + def crear_tablero(self): + """Crea el tablero del juego""" + # Crear cuadrícula + for i in range(0, 480, 30): + for j in range(0, 480, 30): + self.canvas.create_rectangle( + i, j, i+30, j+30, + fill='gray10', + outline='gray20' + ) + + # Crear comida inicial + self.canvas.create_text( + self.posicion_food[0], + self.posicion_food[1], + text='🍎', + fill='red2', + font=('Arial', 18), + tag='food' + ) + + # Crear serpiente inicial + self.canvas.create_text( + *self.posicion_snake[0], + text='▀', + fill='lime green', + font=('Arial', 20), + tag='snake' + ) + + def cambiar_direccion(self, nueva_direccion): + """Cambia la dirección de la serpiente""" + if not self.juego_activo or self.juego_pausado: + return + + direcciones_opuestas = { + 'up': 'down', + 'down': 'up', + 'left': 'right', + 'right': 'left' + } + + if self.direction != direcciones_opuestas.get(nueva_direccion): + self.direction = nueva_direccion + + def calcular_nueva_posicion(self): + """Calcula la nueva posición de la cabeza de la serpiente""" + if self.direction == 'up': + self.y -= 30 + if self.y < 15: + self.y = 465 + elif self.direction == 'down': + self.y += 30 + if self.y > 465: + self.y = 15 + elif self.direction == 'left': + self.x -= 30 + if self.x < 15: + self.x = 465 + elif self.direction == 'right': + self.x += 30 + if self.x > 465: + self.x = 15 + + return (self.x, self.y) + + def mover_serpiente(self): + """Mueve la serpiente""" + if not self.juego_activo or self.juego_pausado: + return + + # Calcular nueva posición + nueva_cabeza = self.calcular_nueva_posicion() + + # Verificar colisión consigo misma + if nueva_cabeza in self.posicion_snake and len(self.posicion_snake) >= 4: + self.game_over() + return + + # Actualizar posición de la serpiente + self.posicion_snake.insert(0, nueva_cabeza) + + # Verificar si comió la manzana + if nueva_cabeza == self.posicion_food: + self.comer_manzana() + else: + self.posicion_snake.pop() + + # Actualizar visualización + self.actualizar_canvas() + + # Verificar victoria + if len(self.posicion_snake) >= 257: + self.victoria() + return + + # Continuar el juego + self.ventana.after(self.velocidad, self.mover_serpiente) + + def comer_manzana(self): + """Lógica cuando la serpiente come una manzana""" + # Reproducir sonido + try: + mixer.music.load("assets/audio_snake.mp3") + mixer.music.play(loops=0) + except: + pass + + # Actualizar puntuación + puntuacion = len(self.posicion_snake) + self.lbl_puntuacion['text'] = f'Puntuación 🍎: {puntuacion}' + + # Generar nueva comida + self.generar_comida() + + def generar_comida(self): + """Genera una nueva posición para la comida""" + while True: + self.posicion_food = ( + random.choice(self.posiciones_validas), + random.choice(self.posiciones_validas) + ) + if self.posicion_food not in self.posicion_snake: + break + + self.canvas.coords(self.canvas.find_withtag("food"), self.posicion_food) + + def actualizar_canvas(self): + """Actualiza la visualización de la serpiente""" + # Eliminar serpiente anterior + self.canvas.delete("snake") + + # Dibujar serpiente nueva + for i, pos in enumerate(self.posicion_snake): + color = 'lime green' if i == 0 else 'green2' + self.canvas.create_text( + *pos, + text='▀', + fill=color, + font=('Arial', 20), + tag='snake' + ) + + def iniciar_juego(self): + """Inicia el juego""" + if not self.juego_activo: + self.juego_activo = True + self.juego_pausado = False + self.direction = 'right' + self.btn_iniciar.config(state='disabled') + self.btn_pausar.config(state='normal') + self.mover_serpiente() + + def pausar_juego(self): + """Pausa o continúa el juego""" + if not self.juego_activo: + return + + self.juego_pausado = not self.juego_pausado + + if self.juego_pausado: + self.btn_pausar.config(text='▶ CONTINUAR', bg='lime green', fg='white') + self.mostrar_pausa() + else: + self.btn_pausar.config(text='⏸ PAUSAR', bg='yellow', fg='black') + self.canvas.delete("pausa") + self.mover_serpiente() + + def mostrar_pausa(self): + """Muestra mensaje de pausa""" + self.canvas.create_text( + 240, 240, + text='PAUSA\n\nPresiona ESPACIO\no clic en CONTINUAR', + fill='yellow', + font=('Arial', 20, 'bold'), + tag='pausa' + ) + + def resetear_juego(self): + """Reinicia el juego""" + # Detener juego actual + self.juego_activo = False + self.juego_pausado = False + + # Reiniciar variables + self.x = 15 + self.y = 15 + self.direction = '' + self.posicion_snake = [(75, 75)] + self.posicion_food = (15, 15) + + # Limpiar canvas + self.canvas.delete(ALL) + + # Recrear tablero + self.crear_tablero() + + # Reiniciar puntuación + self.lbl_puntuacion['text'] = 'Puntuación 🍎: 1' + + # Habilitar botón iniciar + self.btn_iniciar.config(state='normal') + self.btn_pausar.config(state='disabled', text='⏸ PAUSAR', bg='yellow', fg='black') + + def game_over(self): + """Muestra pantalla de game over""" + self.juego_activo = False + self.canvas.delete(ALL) + self.canvas.create_text( + 240, 240, + text=f'GAME OVER\n\nPuntuación Final: {len(self.posicion_snake)}\n\n🍎\n\nPresiona RESET\npara jugar de nuevo', + fill='red', + font=('Arial', 20, 'bold') + ) + self.btn_iniciar.config(state='disabled') + self.btn_pausar.config(state='disabled') + + def victoria(self): + """Muestra pantalla de victoria""" + self.juego_activo = False + self.canvas.delete(ALL) + self.canvas.create_text( + 240, 240, + text='¡EXCELENTE!\n\n°° VICTORIA °°\n\n🍎🍎🍎\n\n¡Completaste el juego!', + fill='lime green', + font=('Arial', 25, 'bold') + ) + self.btn_iniciar.config(state='disabled') + self.btn_pausar.config(state='disabled') + + def salir(self): + """Cierra el juego""" + self.ventana.destroy() + self.ventana.quit() + + +# Ejecutar el juego +if __name__ == "__main__": + ventana = Tk() + juego = SnakeGame(ventana) + ventana.mainloop() \ No newline at end of file diff --git a/Tkinter y Matplotlib Grafica Seno - Slider/grafica_matplotlib_scale.py b/Tkinter y Matplotlib Grafica Seno - Slider/grafica_matplotlib_scale.py index 55f8144..e87187e 100644 --- a/Tkinter y Matplotlib Grafica Seno - Slider/grafica_matplotlib_scale.py +++ b/Tkinter y Matplotlib Grafica Seno - Slider/grafica_matplotlib_scale.py @@ -7,7 +7,6 @@ import numpy as np import matplotlib.pyplot as plt - fig, ax = plt.subplots(dpi=90, figsize=(7,5),facecolor='#00faafb7') plt.title("Grafica en Tkinter con Matplotlib",color='red',size=16, family="Arial") @@ -18,29 +17,22 @@ ax.axhline(linewidth=2, color='r') ax.axvline(linewidth=2, color='r') - ax.set_xlabel("Eje Horizontal", color='black') ax.set_ylabel("Eje Vertical", color='black') ax.tick_params(direction='out', length=6, width=2, colors='black', grid_color='r', grid_alpha=0.5) - def graficar_datos(): nivel = scale.get() x = np.arange(-np.pi, 4*np.pi, 0.01) - line, = ax.plot(x, nivel*np.sin(x), color ='b', linestyle='solid') canvas.draw() - label.config(text= nivel) - line.set_ydata(np.sin(x)+10) - ventana.after(100, graficar_datos) - ventana = Tk() ventana.geometry('642x498') ventana.wm_title('Grafica Matplotlib con Scale') @@ -61,6 +53,5 @@ def graficar_datos(): style = ttk.Style() style.configure("Horizontal.TScale", background= 'gray22') - ventana.mainloop()