20- Programa de paint en Python
Codigo:
from Tkinter import *
canvas_width = 500
canvas_height = 150
def paint(event):
x1,y1 = (event.x - 1),(event.y - 1)
x2,y2 = (event.x + 1),(event.y + 1)
panel.create_oval(x1,y1,x2,y2, fill = "red")
def borrartodo():
panel.delete("all")
master = Tk()
master.title("Pinta con el mouse")
panel = Canvas(master, width = canvas_width, height = canvas_height)
panel.pack(expand = YES, fill = BOTH )
panel.bind("", paint)
mensaje = Label(master, text = "Presione o arrastre con el mouse")
mensaje.pack(side = BOTTOM)
boton = Button(master, text = "Borrar", command = borrartodo)
boton.pack(side = BOTTOM)
master.mainloop()
21- Crear una figura en PyCharm
Código:
from Tkinter import *
ventana=Tk() #hago un objeto ventana
ventana.title('Hace un poligono')#pongo titulo a mi ventana
ventana.config(bg='gray')
ventana.geometry('1147x709')
def poligono(ventana):
panel = Canvas(width = 1148, height = 700, bg='light blue')
panel.pack()
#casa
panel.create_rectangle(100, 410, 370, 650, width = 2, fill= 'yellow', outline = 'black')
#tejado
panel.create_polygon(70, 409, 400, 409, 245, 200, width = 2, fill= 'red', outline = 'black')
#ventanas
panel.create_rectangle(120, 420, 200, 500, width = 2, fill= 'blue', outline = 'black' )
panel.create_rectangle(270, 420, 350, 500, width = 2, fill='purple', outline = 'black')
#Puerta
panel.create_rectangle(200,550, 260, 650, width = 2, fill = 'red', outline = 'black')
panel.create_line(230, 550, 230, 650, width = 2, fill = "black")
panel.create_oval(215, 600, 200, 620, width = 2, fill = 'brown', outline = 'black')
#pasto
panel.create_rectangle(1, 650, 1147, 700, width = 2, fill = 'green', outline = 'black' )
#arbol
panel.create_rectangle(600, 410, 570, 650, width = 2, fill= 'brown', outline = 'black')
panel.create_oval(700, 550, 480, 350, width = 2, fill = 'green', outline = 'black')
#sol
panel.create_oval(1000,150, 880, 50, width = 2, fill = 'yellow', outline = 'black')
panel.create_line(900, 200, 1000, 1, width = 10, fill = "yellow")
panel.create_line(780, 125, 1100, 70, width = 10, fill ="yellow")
panel.create_line(1050, 200, 880, 10, width = 10, fill ="yellow")
boton1 = Button(ventana, text = 'haga poligono', command = lambda:poligono(ventana))
boton1.pack()
ventana.mainloop()
Comentarios
Publicar un comentario