#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    26
    Rep Power
    0

    Display data on tkinter window


    self.after(100, self.serial_process)

    I don't want to update the Tkinter screen for every 100ms.

    one pc is communicating with other pc.
    when one pc sends data, the other pc receives data and display's on tk window. I want this received data on the tk window until it receives one more data from transmitting pc.
    when one more data received, the tk window should update with this data and display it until it receives other data from transmitter.
    This process has to be done every time transmitter sends data.
    The time period between the transmitted data is uneven.
    It may transmit data in 1 min, or on 4 min or may be in 10 min.
    Irrespective of time period between the transmitted data, the receiver pc has to receive and display on the tk window.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Could you be a bit more specific?


    data = 0
    while True:
    if data != incoming_data:
    print 'Notification'
    data = incoming_data

    Sumthing like that doesn't work?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    26
    Rep Power
    0
    Originally Posted by J Dihzy
    Could you be a bit more specific?


    data = 0
    while True:
    if data != incoming_data:
    print 'Notification'
    data = incoming_data

    Sumthing like that doesn't work?


    Two pc's are connected with RS 232 label for serial communication. one pc for transmitting and other pc for receiving.
    I will run this code in receiving pc.
    This code is to receive text from a transmitting pc and display it on tkinter window of the receiving pc.
    The received text has to be displayed on tk window Until it receives other text from transmiting pc.
    But With my code the contents of the received text is displaying on tk window for only few milliseconds, then after tk window looks plain with no contents of data. When it receives another text from transmitter, it again displays the text only for milliseconds and the text vanishes.

    Here
    The text is not a pre defined bunch of messages of equal lengh, the length of the text vary all the time.
    The time period between the text's is not constant, it also vary all the time.
    The transmitter sends text at differnet time periods,first text in 5 min, next text may be in 10 min and the third text may be in 30 min and so on. I don't want to clear the contents of the text from the tk window until it receives other text from transmitter.

    The font size i choose is 37 and I dont need a scrool bar to scrool the window, because transmitter sends maximum of 5 lines to display on receiver tk widow.

    THE DATA WHICH IS DISPLAYING ON TKINTER WINDOW SHOULD KEEP ON DISPLAYING UNTIL IT RECEIVES DATA AGAIN FROM TRANSMITTER.




    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)
            
            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.insert('end', self.queue.get())
                except Queue.Empty:
                    pass
            self.after(1500, self.process_serial)
    
    app = App()
    app.mainloop()

IMN logo majestic logo threadwatch logo seochat tools logo