1. I have two made continuous graph of data like in CRO in python, for 2 or 4 channels depending on need.
2. When graph reaches right corner it again starts from left again. Right now random values are printed which I will replace with voltage values.
3. Didn't use matplotlib since I didn't find how to do that.
4. Code for this is below. ( special thx to @strantor for that, I had some issues)
5. What I do when i reach horizontal pixel, first I delete it completely, then I print the value on it.
Now how to print grid on it. It gets deleted also.
6. I also tried to put grid image on canvas & then tried to put graph on it, but then that images also gets deleted pixel by pixel.
7. Any way to do that or workaround.
(In actual I have to print graph right to left like in CRO, bur currently i am doing left to right as it is easy).
2. When graph reaches right corner it again starts from left again. Right now random values are printed which I will replace with voltage values.
3. Didn't use matplotlib since I didn't find how to do that.
4. Code for this is below. ( special thx to @strantor for that, I had some issues)
5. What I do when i reach horizontal pixel, first I delete it completely, then I print the value on it.
Now how to print grid on it. It gets deleted also.
6. I also tried to put grid image on canvas & then tried to put graph on it, but then that images also gets deleted pixel by pixel.
7. Any way to do that or workaround.
(In actual I have to print graph right to left like in CRO, bur currently i am doing left to right as it is easy).
Python:
import Tkinter
from Tkinter import *
from random import randint
class pixelTron():
def __init__(self):
self.hor_pixel = 5 #starting point of horizontal pixel
self.old_ver_pixel_1 = 0 #last pixel value of graph 1
self.old_ver_pixel_2 = 302 #last pixel value of graph 2
self.new_ver_pixel_1 = 0 #new pixel value of graph 1
self.new_ver_pixel_2 = 0 #new pixel value of graph 2
self.y0_1 = 0 # y cordinate of graph 1 & 2
self.y1_1 = 0
self.y0_2 = 0
self.y1_2 = 0
self.screen = Tkinter.Tk()
self.running = 1
self.screen.protocol("WM_DELETE_WINDOW", self.suicide)
def pixel(self, C):
nP1 = self.new_ver_pixel_1
oP1 = self.old_ver_pixel_1
nP2 = self.new_ver_pixel_2
oP2 = self.old_ver_pixel_2
hP = self.hor_pixel
if(nP1 == oP1):
nP1 = nP1 + 1
if(nP2 == oP2):
nP2 = nP2 + 1
if(nP1 > oP1):
self.y0_1 = oP1
self.y1_1 = nP1
else:
self.y0_1 = nP1
self.y1_1 = oP1
if(nP2 > oP2):
self.y0_2 = oP2
self.y1_2 = nP2
else:
self.y0_2 = nP2
self.y1_2 = oP2
coord = hP, self.y0_1, hP, self.y1_1
coord2 = hP, self.y0_2, hP, self.y1_2
print coord2
hP = hP + 1
if(hP > 400):
hP = 5;
self.old_ver_pixel_1 = nP1
self.old_ver_pixel_2 = nP2
C.create_line(hP , 0 , hP , 300, fill = 'black')
C.create_line(hP , 302 , hP , 602, fill = 'black')
C.create_line(coord, fill = 'red')
C.create_line(coord2, fill = 'yellow')
C.pack()
self.hor_pixel = hP
def graph(self):
screen = self.screen
graph_index(screen)
screen.title("Analog Channel")
screen.geometry("800x800")
C = Tkinter.Canvas(screen , bg = "black", width = 600, height = 602)
C.create_line(5 , 301 , 400 , 301, fill = 'white')
#photo = PhotoImage(file="../untitled.gif")
#C.create_image(0,0 ,image = photo)
C.pack()
pixel = self.pixel
while self.running:
self.new_ver_pixel_1 = randint(0,300);
self.new_ver_pixel_2 = randint(0,300) + 302;
screen.after(100,pixel(C))
screen.update()
screen.mainloop()
def suicide(self):
self.running = 0
self.screen.destroy()
def my_graph():
PT = pixelTron()
PTG = PT.graph
PTG()
def graph_index(screen):
label = Label(screen , text = "-20")
label.pack()
label.place(x = 70, y = 270)
label = Label(screen , text = "-10")
label.pack()
label.place(x = 70, y = 215)
label = Label(screen , text = "0")
label.pack()
label.place(x = 80, y = 140)
label = Label(screen , text = "+10")
label.pack()
label.place(x = 70, y = 65)
label = Label(screen , text = "+20")
label.pack()
label.place(x = 70, y = 0)
label = Label(screen , text = "+20")
label.pack()
label.place(x = 70, y = 302)
label = Label(screen , text = "+10")
label.pack()
label.place(x = 70, y = 375)
label = Label(screen , text = "0")
label.pack()
label.place(x = 80, y = 450)
label = Label(screen , text = "-10")
label.pack()
label.place(x = 70, y = 525)
label = Label(screen , text = "-20")
label.pack()
label.place(x = 70, y = 600)
my_graph()
Last edited by a moderator: