Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to display variable serial data on Tkinter window.
#1
This code is to receive serial data and to print on the TKinter window. The received data prints on the window from top to bottom.

My question is @
In breif:The font i choose is 37 in my code.with this font size i can receive and print 9 lines on the Tkinter window. If i receive 1 line of data,this data should print on 5th line, by leaving equal amount of space at top and bottom of the window.Again i may receive 3 line of serial data, this data should print from 4th to 6th line of the window by leaving equal space on top and bottom.Again if i receive 6 lines of serial data, this should print from 2nd line to 7th line on the window. Irrespective of data size, data should print on window,by leaving equal amount of spaces at top and bottom of the window. This display will make a good impression to see on the window.
So what i have to do in my code to achieve this kind of display. please help me out. thanks.

[/code]import serial
import threading
import Queue
import Tkinter as tk
class SerialThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
s = serial.Serial('COM10',9600, timeout=10)
s.bytesize = serial.EIGHTBITS #number of bits per bytes
s.parity = serial.PARITY_NONE #set parity check: no parity
s.stopbits = serial.STOPBITS_ONE #number of stop bits
while True:
if s.inWaiting():
text = s.readline(s.inWaiting())
self.queue.put(text)
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.geometry("1360x750")
frameLabel = tk.Frame(self, padx=40, pady =40)
self.text = tk.Text(frameLabel, wrap='word', font='TimesNewRoman 37',
bg=self.cget('bg'), relief='flat')
frameLabel.pack()
self.text.pack()
self.queue = Queue.Queue()
thread = SerialThread(self.queue)
thread.start()
self.process_serial()
def process_serial(self):
self.text.delete(1.0, 'end')
while self.queue.qsize():
try:
self.text.delete(1.0, 'end') # to delete previous content on window
self.text.insert('end', self.queue.get())
except Queue.Empty:
pass
self.after(100, self.process_serial)
app = App()
app.mainloop()[code]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fetch data from a web page hami1981 1 1,194 09-05-2014, 01:45 PM
Last Post: hami1981
  Window closes when opened Reality 5 1,254 08-11-2010, 01:07 PM
Last Post: Daniel Faraday
  [Tutorial] Advanced Tkinter Calculator uber1337 8 5,327 04-06-2010, 11:51 AM
Last Post: uber1337
  Tkinter movable Dot? nevets04 4 1,846 03-06-2010, 05:26 PM
Last Post: nevets04
  Complete Tkinter Calculator uber1337 0 1,698 03-06-2010, 09:49 AM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 1 Guest(s)