Is there any sample code to draw parabola using Tkinter? 2 3233
Here is an old piece of code I wrote when begining Python ;-)
from Tkinter import *
import string
import Numeric
from Canvas import Line
import math
class Tableau(Canvas):
def
__init__(self,master=None,size=400,col='black',col rep='red',colgrid='grey'):
Canvas.__init__(self,master,width=size,height=size ,bg=col,highlightthickness=0)
self.pack(expand=1,fill=BOTH)
self.width_table = 0; self.height_table = 0
self.nl = 20.0
self.bind("<Configure>",self.Redraw)
self.colrep = colrep
self.colgrid = colgrid
def GetSize(self,event):
self.width_table = event.width
self.height_table = event.height
def SetBgColor(self,color):
self['bg'] = color
def ChangeColGrid(self,col):
self.colgrid = col
self.itemconfig('grid',fill=col)
def ChangeColAxe(self,col):
self.colrep = col
self.itemconfig('repere',fill=col)
def Redraw(self,event):
self.delete('all')
self.TraceAxe()
self.UpdateGraphe()
self.update()
def Redessine(self):
self.delete('all')
self.TraceAxe()
#self.UpdateGraphe()
self.update()
def TraceAxe(self):
self.delete('all')
w , h = self.winfo_width(),self.winfo_height()
#Trace Grille
posx=0;posy=0
intervallex = w/self.nl
intervalley = h/self.nl
posx=intervallex;posy=intervalley
for i in range(0,self.nl):
self.create_line(posx,0,posx,h,fill=self.colgrid,t ag=('repere','grid'))
self.create_line(0,posy,w,posy,fill=self.colgrid,t ag=('repere','grid'))
posy += intervalley
posx += intervallex
#Trace des axes
posx = w/2.0; posy = h/2.0
self.create_line(posx,0,posx,h,fill=self.colrep,ta g=('repere','axe'))
self.create_line(0,posy,w,posy,fill=self.colrep,ta g=('repere','axe'))
def UpdateGraphe(self):
for f in F.keys():
try:
name,color = F[f]
Function(f,nom=name,col=color)
except:
Function(f)
class Function:
def __init__(self,fonction = '',nom='affine',col='yellow',epaiss =
1):
w , h = t.winfo_width(),t.winfo_height()
self.valeur = eval('lambda x: '+fonction)
self.x = Numeric.arange(-200.0,200.0)
self.y = 20*self.valeur(self.x/20.0)
res = Numeric.arange(0.0,800.0)
res.shape = (400,2)
res[:,0] = self.x*w/400.0 + w/2.0
res[:,1] = -self.y*h/400.0 + h/2.0
Line(t,res.tolist(),fill=col,tag=nom,width=epaiss)
def expression(exp):
return eval('lambda x: '+exp)
if __name__ == '__main__':
print "test"
sin = Numeric.sin
F =
{'x*x':('carre','green'),'2*sin(x)':('sin','blue') ,'x*x*x':('cube','yellow')}
t = Tableau()
t.delete('grid')
t.mainloop()
from Tkinter import *
import string
import Numeric
from Canvas import Line
import math
class Tableau(Canvas):
def
__init__(self,master=None,size=400,col='black',col rep='red',colgrid='grey'):
Canvas.__init__(self,master,width=size,height=size ,bg=col,highlightthickness=0)
self.pack(expand=1,fill=BOTH)
self.width_table = 0; self.height_table = 0
self.nl = 20.0
self.bind("<Configure>",self.Redraw)
self.colrep = colrep
self.colgrid = colgrid
def GetSize(self,event):
self.width_table = event.width
self.height_table = event.height
def SetBgColor(self,color):
self['bg'] = color
def ChangeColGrid(self,col):
self.colgrid = col
self.itemconfig('grid',fill=col)
def ChangeColAxe(self,col):
self.colrep = col
self.itemconfig('repere',fill=col)
def Redraw(self,event):
self.delete('all')
self.TraceAxe()
self.UpdateGraphe()
self.update()
def Redessine(self):
self.delete('all')
self.TraceAxe()
#self.UpdateGraphe()
self.update()
def TraceAxe(self):
self.delete('all')
w , h = self.winfo_width(),self.winfo_height()
#Trace Grille
posx=0;posy=0
intervallex = w/self.nl
intervalley = h/self.nl
posx=intervallex;posy=intervalley
for i in range(0,self.nl):
self.create_line(posx,0,posx,h,fill=self.colgrid,t ag=('repere','grid'))
self.create_line(0,posy,w,posy,fill=self.colgrid,t ag=('repere','grid'))
posy += intervalley
posx += intervallex
#Trace des axes
posx = w/2.0; posy = h/2.0
self.create_line(posx,0,posx,h,fill=self.colrep,ta g=('repere','axe'))
self.create_line(0,posy,w,posy,fill=self.colrep,ta g=('repere','axe'))
def UpdateGraphe(self):
for f in F.keys():
try:
name,color = F[f]
Function(f,nom=name,col=color)
except:
Function(f)
class Function:
def __init__(self,fonction = '',nom='affine',col='yellow',epaiss =
1):
w , h = t.winfo_width(),t.winfo_height()
self.valeur = eval('lambda x: '+fonction)
self.x = Numeric.arange(-200.0,200.0)
self.y = 20*self.valeur(self.x/20.0)
res = Numeric.arange(0.0,800.0)
res.shape = (400,2)
res[:,0] = self.x*w/400.0 + w/2.0
res[:,1] = -self.y*h/400.0 + h/2.0
Line(t,res.tolist(),fill=col,tag=nom,width=epaiss)
def expression(exp):
return eval('lambda x: '+exp)
if __name__ == '__main__':
print "test"
sin = Numeric.sin
F =
{'x*x':('carre','green'),'2*sin(x)':('sin','blue') ,'x*x*x':('cube','yellow')}
t = Tableau()
t.delete('grid')
t.mainloop()
Here is an old piece of code I wrote to test Tkinter
from Tkinter import *
import string
import Numeric
from Canvas import Line
import math
class Tableau(Canvas):
def
__init__(self,master=None,size=400,col='black',col rep='red',colgrid='grey'):
Canvas.__init__(self,master,width=size,height=size ,bg=col,highlightthickness=0)
self.pack(expand=1,fill=BOTH)
self.width_table = 0; self.height_table = 0
self.nl = 20.0
self.bind("<Configure>",self.Redraw)
self.colrep = colrep
self.colgrid = colgrid
def GetSize(self,event):
self.width_table = event.width
self.height_table = event.height
def SetBgColor(self,color):
self['bg'] = color
def ChangeColGrid(self,col):
self.colgrid = col
self.itemconfig('grid',fill=col)
def ChangeColAxe(self,col):
self.colrep = col
self.itemconfig('repere',fill=col)
def Redraw(self,event):
self.delete('all')
self.TraceAxe()
self.UpdateGraphe()
self.update()
def Redessine(self):
self.delete('all')
self.TraceAxe()
#self.UpdateGraphe()
self.update()
def TraceAxe(self):
self.delete('all')
w , h = self.winfo_width(),self.winfo_height()
#Trace Grille
posx=0;posy=0
intervallex = w/self.nl
intervalley = h/self.nl
posx=intervallex;posy=intervalley
for i in range(0,self.nl):
self.create_line(posx,0,posx,h,fill=self.colgrid,t ag=('repere','grid'))
self.create_line(0,posy,w,posy,fill=self.colgrid,t ag=('repere','grid'))
posy += intervalley
posx += intervallex
#Trace des axes
posx = w/2.0; posy = h/2.0
self.create_line(posx,0,posx,h,fill=self.colrep,ta g=('repere','axe'))
self.create_line(0,posy,w,posy,fill=self.colrep,ta g=('repere','axe'))
def UpdateGraphe(self):
for f in F.keys():
try:
name,color = F[f]
Function(f,nom=name,col=color)
except:
Function(f)
class Function:
def __init__(self,fonction = '',nom='affine',col='yellow',epaiss =
1):
w , h = t.winfo_width(),t.winfo_height()
self.valeur = eval('lambda x: '+fonction)
self.x = Numeric.arange(-200.0,200.0)
self.y = 20*self.valeur(self.x/20.0)
res = Numeric.arange(0.0,800.0)
res.shape = (400,2)
res[:,0] = self.x*w/400.0 + w/2.0
res[:,1] = -self.y*h/400.0 + h/2.0
Line(t,res.tolist(),fill=col,tag=nom,width=epaiss)
def expression(exp):
return eval('lambda x: '+exp)
if __name__ == '__main__':
print "test"
sin = Numeric.sin
F =
{'x*x':('carre','green'),'2*sin(x)':('sin','blue') ,'x*x*x':('cube','yellow')}
t = Tableau()
t.delete('grid')
t.mainloop() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John J. Lee |
last post by:
I've put together a Python package for scraping / testing pages that
depend on embedded JavaScript code (without depending on IE, Mozilla
or Konqueror, and with the DOM etc. all implemented in pure...
|
by: Baloff |
last post by:
Hello group
Is there a library which can help in doing the task below or do I need
to write something up?
I need to get the index of the relative “local” maximas and minimas in a
sequence or...
|
by: Shawn B. |
last post by:
Greetings,
I have a troubling issue that I'm not sure how to approach at this point.
Given the HTML tag (any tag will do):
<div id='divSomething' onmouseover='...'>Next we write...
|
by: Earl |
last post by:
I have an image issue that I do not understand. When I try to save a bitmap
created from a picturebox image, I can save without exception so long as the
bitmap was retrieved from a file and loaded...
|
by: Mr. SweatyFinger |
last post by:
where have they all gone.
alt.suicide?
alt.findContol.then.slit.your.own.throat?
|
by: ghafarianm |
last post by:
Hi all dear friends
I would like to as you if you can kindly help me with this assignment .
here is the link of complete task:
http://www.cs.ryerson.ca/dhamelin/cps118/a/a1-fall2007.pdf
...
|
by: lavanya2284 |
last post by:
Hi frnds.
I am a VB 6.0 programmer.I have to draw a parabola or (U - shaped Curve ) on the picture box.its really urgent.Help me out.
Thanks in advance.
Latha.M
|
by: serdar |
last post by:
Hi,
I'll use a function called A-weighting Filter for a spectrum analyzer I'm designing in Flash. Here is the equation of A-Weighting Filter:
...
|
by: cloud255 |
last post by:
Hi,
Not sure if this qualifies as advanced math, but I'm not sure how to approach this problem.
I use the standard formula:
y = ax^2 + bx + c where x<= 0, c=0, y>=0, b=0
so it can be...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |