kvar 0 Newbie Poster

Hello, I'm a newbie in python.
I've written a code for websocket for server and client communication. here im getting some data from server ( "sprintf(buffer,<STX,250,350,254,%d,858,STX>, i) and im saving this to RPI which is my client. now i've to display these readings on a window using tkinter. i've created an image to displat these values but the problem is that im getting only the starting value of the sprintf and it's not getting update every second. i've used .after() and update() but no use to it. any help would be a great from your side. im uploading my code and thanks in advance

CODE :

importing libraries

from Tkinter import *
import Tkinter as Tk
import Tkinter as tk
import websocket
import time

Tkinter window for image background

window = tk.Tk()

defining colors

colors = ["#FF0000","#008000","#0000FF","#FFFF00","#FF8000","#000000","#FFFFFF",
"#A52A2A","#00EEEE","#FF00FF","#800080","#FFC0CB","#BDFCC9","#000080",
"#4B0082","#292421","#F0E68C","#7CFC00","#F08080","#20B2AA","#B0C4DE",
"#03A89E","#FF8000","#DA70D6","#33A1C9","#FA8072","#FFE1FF","#C6E2FF"]

creating variables

width_value = window.winfo_screenwidth()
height_value = window.winfo_screenheight()
image_bg = colors[4]
tittle_txt = "DATA LOGGER READINGS"
tittle_fg = colors[8]
tittle_bg = colors[6]
tittle_font = ("Times Roman",65)
x_coords = 420
y_coords = 0
fixed_txt = "Target = "
txt_fg = colors[0]
txt_font = ("Helvetica",35)
txt_bg = colors[5]

server and client communication

ws = websocket.WebSocket()
ws.connect("ws://192.168.4.1/")
while 1:
result = ws.recv()
print(result)

creating image attributes and coordinates

window.attributes("-fullscreen",True)
window.config(highlightthickness = 0)

creating text, font, bg, fg, label, x and y coords

canvas = Canvas(window, width = width_value, height = height_value, bg = image_bg)
tittle = Label(window, text = tittle_txt, fg = tittle_fg, font = tittle_font, bg = tittle_bg).place(x = x_coords, y = y_coords)
label1 = Label(window, text = fixed_txt+str(result), fg = txt_fg, font = txt_font, bg = txt_bg).place(x = label1_x_coords, y = label1_y_coords)
window.update()
canvas.pack()
window.mainloop()

ws.close()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.