I have a small Tkinter app to show some serial communication. It has two Text components (user_input and log) and a 'Send' button.
When 'Send' is pressed, whatever written in user_input is sent to the serial.
def send_clicked(self):
data = self.user_input.get(1.0, END)[:-1] + '\0'
self.serial.write(str(data))
self.user_input.delete(1.0, END)
Also this method runs every 100 millis to display serial output in log Text component:
def read_serial(self):
self.log.update() # display input text
self._read_character()
self.after(100, self.read_serial) # check serial again soon
def _read_character(self):
c = self.serial.read() # attempt to read a character from Serial
# was anything read?
while len(c) > 0:
# get the buffer from outside of this function
# check if character is a delimeter
if c == '\r':
c = '' # don't want returns. chuck it
if c == '\n':
self.serial_buffer += "\n" # add the newline to the buffer
self.log.insert(END, self.serial_buffer)
self.log.yview(END)
self.serial_buffer = "" # empty the buffer
else:
self.serial_buffer += c # add to the buffer
c = self.serial.read()
This works fine in windows, linux and mac.
Now I want to print ">> value" on the responses Text when the user clicks 'Send', so I redefine send_clicked:
def send_clicked(self):
data = self.user_input.get(1.0, END)[:-1] + '\0'
self.serial.write(str(data))
self.log.insert(END, '>> %s\n' % data)
self.log.yview(END)
self.user_input.delete(1.0, END)
This causes the window to stop refreshing in MacOS (it works fine in linux and windows), I have to click outside the window and click back for it to refresh. Now I've aded a menu, I can also click a button in the menu to get an update.
If you're running OSX 10.9 (Mavericks), it is likely that this is the issue. I suggest updating your current version of Tcl/Tk or even updating to the latest version of Python (especially if you are still using 3.3). Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With