1 / 12

from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200) cv.pack()

from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200) cv.pack() cv.create_rectangle(20,40,100,100) cv.create_rectangle(100,100,180,160,fill="black") ventana.mainloop(). from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200) cv.pack()

keefe
Download Presentation

from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200) cv.pack()

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200) cv.pack() cv.create_rectangle(20,40,100,100) cv.create_rectangle(100,100,180,160,fill="black") ventana.mainloop()

  2. from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200) cv.pack() cv.create_oval(20,40,100,100) cv.create_oval(100,100,200,200,fill="black") ventana.mainloop()

  3. #circunferencias al azar from Tkinter import * import random def dibujar(): x=random.randint(0,ancho) y=random.randint(0,alto) r=random.randint(1,min(alto,ancho))/2 cv.create_oval(x-r,y-r,x+r,y+r) v=Tk() alto=200; ancho=200 b=Button(v,text="circunferencia",command=dibujar) cv=Canvas(v,width=ancho,height=alto) b.pack(); cv.pack() v.mainloop()

  4. from Tkinter import * ventana=Tk() W=input("ancho?"); H=input("alto?") cv=Canvas(ventana,width=W,height=H,bg="white")#fondo cv.pack() #dibujar ejes cv.create_line(0,H-1,W,H-1) #horizontal cv.create_line(W/2,0,W/2,H) #vertical h0=0; v0=0 #coordenadas comienzo primera linea #iterar con x=-100,-90,…,-10,0,10,…,90,100 x = -100.0 while x<=100 : y=x*x #valor de la función h = int(W*(x+100)/200 + 0.5) #coord horizontal v = H - int(H*y/10000 + 0.5) #coord vertical cv.create_line(h0,v0,h,v) h0=h; v0=v #actualizar coordenadas comienzo línea x = x + 10 ventana.mainloop()

  5. #graficar seno con 20 ptos entre 0 y 2*pi from Tkinter import * import math ventana=Tk() cv=Canvas(ventana,width=200,height=100,bg="white") cv.pack() graficar(math.sin,20,0,2*math.pi,cv,200,100) ventana.mainloop() #graficar x*x con 20 ptos entre -100 y 100 def cuadrado(x): return x*x from Tkinter import * ventana=Tk() cv=Canvas(ventana,width=200,height=200,bg="white") cv.pack() graficar(cuadrado,20,-100,100,cv,200,200) ventana.mainloop()

  6. from Tkinter import * #graficar f usando n puntos de [a,b] en canvas cv de WxH pixeles def graficar(f,n,a,b,cv,W,H): #determinar minimo y maximo de f en [a,b] minimo=f(a) maximo=f(a) delta=(b-a)/(n-1) x=a+delta while x <= b : y=f(x) minimo=min(y,minimo) maximo=max(y,maximo) x = x + delta

  7. #graficar funcion h0=0 v0=H-coordenadaPixel(f(a),minimo,maximo,H) x=a+delta while x<=b: h=coordenadaPixel(x,a,b,W) v=H-coordenadaPixel(f(x),minimo,maximo,H) cv.create_line(h0,v0,h,v) h0=h; v0=v x=x+delta #convertir x en [y,z] a coord [0,w] de pixel def coordenadaPixel(x,y,z,w): return int(w*(x-y)/(z-y)+0.5)

More Related