Quantcast
Viewing all articles
Browse latest Browse all 14040

tkinter destroy error adding text to canvas

I am getting an error alloc: invalid block: 047129A8: c0 4 when I add text to the canvas using create_text

Here is a sample program. If the create_text is removed clicking on the rectangle closes the progamme, but after adding text the programme closes but the error message appears and a popup window saying python has stopped working.

If I replace destroy() with quit(), it works fine.(Python 3.5)

import tkinter as TKclass Button():    def __init__(self):        self.master = TK.Tk()        canvas_width = 200        canvas_height =200        canvas = TK.Canvas(self.master, width=canvas_width,  height=canvas_height)        button = canvas.create_rectangle([10,10,110,30],fill='lightgrey')        canvas.tag_bind(button, "<ButtonPress-1>", self.test) # lambda x: self.action(x,DOWN))          canvas.pack()        canvas_id = canvas.create_text(10, 50, anchor="nw")        canvas.itemconfig(canvas_id, text="this is the text")        TK.mainloop()    def test(self, e):        print ('Clicked')        #self.master.quit()        self.master.destroy()if __name__ == '__main__':    b = Button()

Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>