I am making a game where the balls come from up to down. It isn’t ready, but I have an error that I can’t solve. The error is like that:
Traceback (most recent call last): File "D:numeric.py", line 73, in <module> red() File "D:numeric.py", line 48, in red tahvel.create_oval(oval1y,oval1x,oval1yy,oval1xx,fill="red") File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0libtkinter__init__.py", line 2798, in create_oval return self._create('oval', args, kw) File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0libtkinter__init__.py", line 2776, in _create return self.tk.getint(self.tk.call( _tkinter.TclError: invalid command name ".!canvas"
And my code looks like this:
from tkinter import* from random import* import time #punane pall oval1y=820 oval1x=50 oval1yy=880 oval1xx=110 punane=0 #sinine pall oval2y=920 oval2x=50 oval2yy=980 oval2xx=110 sinine=0 #roheline pall oval3y=1020 oval3x=50 oval3yy=1080 oval3xx=110 roheline=0 #kollane pall oval4y=1120 oval4x=50 oval4yy=1180 oval4xx=110 kollane=0 raam = Tk() raam.title("Tahvel") tahvel = Canvas(raam, width=1900, height=1000, background="black") tahvel.grid() def taust(): tahvel.create_rectangle(800,50,1200,900,fill="grey") tahvel.create_rectangle(890,50,910,900,fill="white") tahvel.create_rectangle(990,50,1010,900,fill="white") tahvel.create_rectangle(1090,50,1110,900,fill="white") taust() a=1#randint(1,4) def red(): print("1") global oval1x global oval1xx if a==1: tahvel.create_oval(oval1y,oval1x,oval1yy,oval1xx,fill="red") punane=1 if punane==1: punane=0 for i in range(100): oval1x +=10 oval1xx +=10 time.sleep(1) taust() tahvel.create_oval(oval1y,oval1x,oval1yy,oval1xx,fill="red") raam.after(100,red) raam.mainloop()
What I am trying to do is to make a repeat where the balls will be moved slightly down. Right now the balls are not moved slightly down cause I want to see the ball movement. But the balls move only once down and then stop. Can someone help me? I would be really thankful.
Anonymous Asked question May 13, 2021
Recent Comments