Re: Moving object on page leaves afterimage on Python 3 but not on 2
Reinis Danne <[email protected]>
| Newsgroups | gmane.comp.python.tkinter |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Feb 05, 2016 at 10:29:42AM +0100, Michael Lange wrote: > Hi, > > On Thu, 4 Feb 2016 14:58:11 +0200 > Reinis Danne <[email protected]> wrote: > > > To test: > > $ git clone https://gitlab.com/bkchem/bkchem.git > > $ cd bkchem > > $ git submodule init > > $ git submodule update > > $ python3 bkchem/bkchem.py > > this looks like quite a complex piece of code. Is it possible for you to > provide a simpler example that exhibits the problem? Ok. With the help of traceback module and some print statements I have isolated where the issue is and provide a small example code in attachment. > Some additional information might also be helpful to track down the > problem: > * which platform are you running (Windows / X / Mac)? I'm running on Gentoo ~amd64 but have tested also on Linux Mint. > * do your Python 2 / 3 versions share the same Tk version? > * which Tk version(s) do you use? > Yes, I have only tk-5.6.4 installed. > Without having reviewed the code I can only try a quick shot in the dark: > maybe Python 2 and 3 do *not* use the same Tk and these Tk versions > behave slightly differently. Maybe inserting additional calls to > update_idletasks() here and there might help. At a quick glance the > redraw() method in your graphics module might be a candidate for this. > Have you already tried that? > > Best regards > > Michael > Thanks for the help! The main drawing routines for BKChem are located in paper.py, but the issue seems to be with bond.py::bond.delete(). It uses map() to call Canvas.delete() for every item in a list. It works in Python 2, but in Python 3 it doesn't delete the item(s). Replacing this: map(self.paper.delete, items) with this: for i in items: self.paper.delete(i) fixes the problem. I don't understand why the difference. That code is equivalent in both cases as far as I know. Is there a bug or I'm using map() incorrectly? Reinis _______________________________________________ Tkinter-discuss mailing list [email protected] https://mail.python.org/mailman/listinfo/tkinter-discuss
test.py
(text/x-python, 599 B)
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.paper = tk.Canvas(self, width=320, height=320)
self.paper.pack()
item = self.paper.create_line(10, 10, 30, 30, fill="black", tags="bond")
print("item", item)
print("bonds", self.paper.find_withtag("bond"))
map(self.paper.delete, [item])
print("bonds", self.paper.find_withtag("bond"))
if __name__ == "__main__":
app = App()
app.mainloop()