how to display irrespective length of serial data on Tkinter Window. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how to display irrespective length of serial data on Tkinter Window.

srinu472srinu472 Posts: 1Member
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 print 9 lines on the 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][/code]import serial
import threading
import Queue
import Tkinter as tk

class SerialThread(threading.Thread):
def __init__(self, queue):
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())

class App(tk.Tk):
def __init__(self):
frameLabel = tk.Frame(self, padx=40, pady =40)
self.text = tk.Text(frameLabel, wrap='word', font='TimesNewRoman 37',
bg=self.cget('bg'), relief='flat')
self.queue = Queue.Queue()
thread = SerialThread(self.queue)

def process_serial(self):
self.text.delete(1.0, 'end')
while self.queue.qsize():
self.text.insert('end', self.queue.get())
except Queue.Empty:
self.after(100, self.process_serial)

app = App()

Sign In or Register to comment.