Elaboramos con Tkinter 4 figuras: Una linea, un ovalo, un rectagulo y una estrella
Figuras:
 

Figuras:
Codigo:
# -*- coding: utf-8 -*-
#figuras con tkinter
import pygame
import time
from Tkinter import *
import tkColorChooser #Libreria para traer paleta de colores
v0 = Tk()
v0.title('Ventana principal')
v0.config(bg='grey')      #fondo  bg color
v0.geometry("565x50")
def mostrar(num):
    if num == 1:
        pygame.init()
        running = True
        window = pygame.display.set_mode((400,400))
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            COLOR =(237,28,36)
            pygame.draw.line(window,COLOR, (25, 260), (375, 260), 4)
            pygame.display.update()
        pygame.display.quit()
    elif num == 2:
        pygame.init()
        running = True
        window = pygame.display.set_mode((400,400))
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            COLOR = (0, 128, 0)
            pygame.draw.rect(window,COLOR, pygame.Rect((25, 275, 350, 100)), 0)
            pygame.display.update()
        pygame.display.quit()
    elif num == 3:
        pygame.init()
        running = True
        window = pygame.display.set_mode((400,400))
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            COLOR= (255,0,255)
            pygame.draw.circle(window,COLOR, (105, 290), 80, 0)
            pygame.display.update()
        pygame.display.quit()
    elif num == 4:
        running = True
        window = pygame.display.set_mode((200, 200))
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            BODYALIEN = (253,106,2)
            pygame.draw.polygon(window, BODYALIEN,
                                [(10, 40), (40, 40), (50, 10), (60, 40), (90, 40), (65, 60), (75, 90), (50, 70),
                                 (25, 90), (35, 60)], 0)
            pygame.display.update()
        pygame.display.quit()
def ocultar(ventana):ventana.destroy()
def ejecutar(f):v0.after(200,f)
#V0 donde se va desplegar el boton
b1=Button(v0,text='Abrir ventana con linea',command=lambda:ejecutar(mostrar(1)))
b1.grid(row=1,column=1)  #desplegar boton
b2=Button(v0,text='Abrir ventana con cuadrado',command=lambda:ejecutar(mostrar(2)))
b2.grid(row=1,column=2)  #desplegar boton
b3=Button(v0,text='Abrir ventana con elipse',command=lambda:ejecutar(mostrar(3)))
b3.grid(row=1,column=3)  #desplegar boton
b4=Button(v0,text='Abrir ventana con figura',command=lambda:ejecutar(mostrar(4)))
b4.grid(row=1,column=4)  #desplegar boton
v0.mainloop()
Comentarios
Publicar un comentario