1. I am trying to plot two graph in Tkinter canvas.
2. Problem is after few plots of data, graph gets hanged.
It takes up huge resources of window, then i have to kill it forcefully.
3. Since I have to plot the graph continuously like that in CRO/DSO so I have to go line by line rather than using any library. Didn't find any lib where graph is printed continuously.
4. I am using python 2.7 on window 8 64 bit.
5. But in the end I have to shift the code to Raspberry pi board.
Edit: code
2. Problem is after few plots of data, graph gets hanged.
It takes up huge resources of window, then i have to kill it forcefully.
3. Since I have to plot the graph continuously like that in CRO/DSO so I have to go line by line rather than using any library. Didn't find any lib where graph is printed continuously.
4. I am using python 2.7 on window 8 64 bit.
5. But in the end I have to shift the code to Raspberry pi board.
Edit: code
Code:
from Tkinter import *
import Tkinter
import time
from random import randint
import math
#global vars
hor_pixel = 5 #starting point of horizontal pixel
old_ver_pixel_1 = 0 #last pixel value of graph 1
old_ver_pixel_2 = 0 #last pixel value of graph 2
new_ver_pixel_1 = 0 #new pixel value of graph 1
new_ver_pixel_2 = 0 #new pixel value of graph 2
y0_1 = 0 # y cordinate of graph 1 & 2
y1_1 = 0
y0_2 = 0
y1_2 = 0
def pixel(C):
global hor_pixel
global old_ver_pixel_1
global old_ver_pixel_2
global new_ver_pixel_1
global new_ver_pixel_2
global y0_1
global y1_1
global y0_2
global y1_2
if(new_ver_pixel_1 == old_ver_pixel_1):
new_ver_pixel_1 = new_ver_pixel_1 + 1
if(new_ver_pixel_2 == old_ver_pixel_2):
new_ver_pixel_2 = new_ver_pixel_2 + 1
if(new_ver_pixel_1 > old_ver_pixel_1):
y0_1 = old_ver_pixel_1
y1_1 = new_ver_pixel_1
else:
y0_2 = old_ver_pixel_2
y1_2 = new_ver_pixel_2
coord = hor_pixel, y0_1, hor_pixel, y1_1
coord2 = hor_pixel, y0_2, hor_pixel, y1_2
hor_pixel = hor_pixel + 1
if(hor_pixel > 400):
hor_pixel = 5;
old_ver_pixel_1 = new_ver_pixel_1
old_ver_pixel_2 = new_ver_pixel_2
C.create_line(hor_pixel , 0 , hor_pixel , 500, fill = 'black')
C.create_line(coord, fill = 'red')
C.create_line(coord2, fill = 'yellow')
C.pack()
#print(new_ver_pixel_1 , new_ver_pixel_2)
def graph():
global new_ver_pixel_1
global new_ver_pixel_2
screen = Tkinter.Tk()
screen.title("Analog Channel")
screen.geometry("800x800")
C = Tkinter.Canvas(screen , bg = "black" , height = 800, width = 800)
C.pack()
while True:
var = 0
var = var + 1
new_ver_pixel_1 = randint(0,200) + 200;
new_ver_pixel_2 = randint(0,200) + 400;
#print(new_ver_pixel_1 , new_ver_pixel_2)
#pixel(C)
screen.after(100,pixel(C))
screen.update_idletasks()
screen.mainloop()
graph()
Attachments
-
793 bytes Views: 1
Last edited: