TKinter crashing very consistently, no error - Raspberry Pi Forums


i have code on phone, post once tethered.

have program running reads in at-most 48 character statement pyserial, displays on canvas. uses after() callback combined tk.destroy() refresh screen every time new message sent.

after 132 134 runs (+/- counting tolerance), crashes out full screen partial-size window tk in title bar , no message, empty gray box. commented out print lines, made output string global instead of local, , still did it.

running terminal, crashed cleanly no errors.

thought might memory leak, think give me error, it's not. plus having 512mb of ram, if factor 48-char serial string , at-most 36 char output string tv, there's no way can see adding 3.84mb per run take run out of memory.

should start (other posting code, give me few minutes)?

i attached file zip. original. after acted first time, commented out print statements thinking causing memory leak, didn't it, made outdata , outdisplay global variables thinking causing memory leak, didn't it, saw tk not initialized globally though defined such, did , still didn't work.

go here? i'm 60% sure related after() callback, don't know how else it?

serial output (as recall master device's manual):

code: select all

wt       9999 lb\r\n hd              1\r\n 
or

code: select all

wt       9999 lb\r\n hd              9\r\n av        9999 lb\r\n 

code: select all

#!/usr/bin/python  tkinter import * time import sleep import serial import traceback  #note tkinter python 2.*, tkinter python 3+ # if using python 3, comment out previous line # , uncomment following line # tkinter import *   ser = serial.serial(     port = '/dev/ttyama0',     #port = '/dev/tty.serial1',     baudrate = 9600,      parity = serial.parity_none,      stopbits = serial.stopbits_one,      bytesize = serial.eightbits,     timeout=2     )   def createdisplay(istring):  global tk  # create tk window - within  # else built.  tk = tk()    tk.bind('<key-escape>', terminate)  tk.bind('<escape>', terminate)  #make full screen  tk.attributes("-fullscreen", true)   #add exit button  btn = button(tk, text="exit", command=terminate)  btn.pack()  #add canvas area ready drawing on, helps make text vertically aligned in frame  canvas = canvas(tk, width=120, height=30)  canvas.pack()  #declare input string type  inputstring = stringvar()  #set input string text  inputstring.set(istring)  #add label  text = label(tk, textvariable=inputstring, font="arial 44 bold")  text.pack()  # start tk main-loop (this updates tk display)  tk.after(1000,updatetext)  tk.mainloop()   def terminate():  global tk  tk.destroy()   def main():  = "welcome new\ngainesville livestock\nauction"  createdisplay(something)  def updatetext():  global tk  print str(ser.inwaiting()) + "\n"  if ( ser.inwaiting() >= 13 ):   outdata = ser.readlines()   print outdata   if outdata[1].strip() == "hd              1":    print "single"    outdisplay = outdata[0][:-2:] + "\n" + outdata[1][:2:] + "    " + outdata[1][2:-2:] + "   "     tk.destroy()    #ser.flushinput()    createdisplay(outdisplay)    tk.after(1000,updatetext)   else:    outdisplay = " " + outdata[0][:-2:] + "\n" + outdata[1][:2:] + "   " + outdata[1][2:-2:] + "   " + "\n" + outdata[2][:-2:]    tk.destroy()    createdisplay(outdisplay)    tk.after(1000,updatetext)  else:   tk.after(1000,updatetext)   main() 


raspberrypi



Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62