Форум программистов, компьютерный форум, киберфорум
Python: GUI, графика
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
 
Рейтинг 4.56/9: Рейтинг темы: голосов - 9, средняя оценка - 4.56
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071

Странная RecursionError из-за update

02.11.2019, 12:11. Показов 2077. Ответов 38
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Здравствуйте! Не понимаю, почему данный код выдаёт RecursionError:
Код
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
from tkinter import *
import time
from threading import Thread
import random
class Kolobok():
    def __init__(self):
        self.img = PhotoImage(file='imgs/kolobok.gif')
        self.x = 30
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
        self.move = self.Move(self.x,self.y,self.sprite)
        self.Move = None
        del(self.Move)
        self.act = self.Act(self.x,self.y,self.sprite)
        self.Act = None
        del(self.Act)
    class Move():
        def __init__(self,x,y,sprite):
            self.x = x
            self.y = y
            self.sprite = sprite
        def right(self,px):
            self.x += px
            canvas.move(self.sprite,px,0)
            root.update()
            root.update_idletasks()
        def left(self,px):
            self.x -= px
            canvas.move(self.sprite,-px,0)
            root.update()
            root.update_idletasks()
        def up(self,px):
            self.y -= px
            canvas.move(self.sprite,0,-px)
            root.update()
            root.update_idletasks()
        def down(self,px):
            self.y += px
            canvas.move(self.sprite,0,px)
            root.update()
            root.update_idletasks()
    class Act():
        def __init__(self,x,y,sprite):
            self.x = x
            self.y = y
            self.sprite = sprite
        def jump(self,px,timeout_up=0.005,timeout_down=0.001):
            for i in range(px):
                self.y -= 1
                canvas.move(self.sprite,0,-1)
                root.update()
                root.update_idletasks()
                time.sleep(timeout_up)
            for i in range(px):
                self.y += 1
                canvas.move(self.sprite,0,1)
                root.update()
                root.update_idletasks()
                time.sleep(timeout_down)
class Ship():
    def __init__(self):
        self.img = PhotoImage(file='imgs/ship.gif')
        self.x = root.winfo_screenwidth() + 25
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
        self.move = self.Move(self.x,self.y,self.sprite)
        self.Move = None
        del(self.Move)
        self.act = self.Act(self.x,self.y,self.sprite)
        self.Act = None
        del(self.Act)
    class Move():
        def __init__(self,x,y,sprite):
            self.x = x
            self.y = y
            self.sprite = sprite
        def right(self,px):
            self.x += px
            canvas.move(self.sprite,px,0)
            root.update()
            root.update_idletasks()
        def left(self,px):
            self.x -= px
            canvas.move(self.sprite,-px,0)
            root.update()
            root.update_idletasks()
        def up(self,px):
            self.y -= px
            canvas.move(self.sprite,0,-px)
            root.update()
            root.update_idletasks()
        def down(self,px):
            self.y += px
            canvas.move(self.sprite,0,px)
            root.update()
            root.update_idletasks()
    class Act():
        def __init__(self,x,y,sprite):
            self.x = x
            self.y = y
            self.sprite = sprite
        def jump(self,px,timeout_up=500,timeout_down=100):
            x = 0
            def up():
                self.y -= 1
                canvas.move(self.sprite,0,-1)
                root.update()
                root.update_idletasks()
                x += 1
                if x < px:
                    root.after(timeout_up,up)
            x = 0
            def down():
                self.y += 1
                canvas.move(self.sprite,0,1)
                root.update()
                root.update_idletasks()
                x += 1
                if x < px:
                    root.after(timeout_down,down)
root = Tk()
root.attributes('-fullscreen',True)
canvas = Canvas(bg='white')
canvas.pack(expand=True,fill='both')
canvas.create_rectangle(0,0,root.winfo_screenwidth(),root.winfo_screenheight(),outline='#00a2e8',fill='#00a2e8')
canvas.create_rectangle(0,root.winfo_screenheight()-30,root.winfo_screenwidth(),root.winfo_screenheight(),outline='green',fill='green')
ship = Ship()
ship1 = Ship()
ship2 = Ship()
personage = Kolobok()
def game_thread():
    while True:
        def f1():
            x = root.winfo_screenwidth()+25
            y = 0
            def motion():
                nonlocal x,y
                ship.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            ship.move.right(root.winfo_screenwidth()+25)
        def f2():
            x = root.winfo_screenwidth()//4
            y = 0
            def motion():
                nonlocal x,y
                ship.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            x = root.winfo_screenwidth()-(root.winfo_screenwidth()//4)+25
            y = 0
            def motion():
                nonlocal x,y
                ship1.move.left(1)
                ship.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            ship.move.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//4
            y = 0
            def motion():
                nonlocal x,y
                ship1.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            ship1.move.right(root.winfo_screenwidth()+25)
        def f3():
            x = root.winfo_screenwidth()//3
            y = 0
            def motion():
                nonlocal x,y
                ship.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            x = root.winfo_screenwidth()//3
            y = 0
            def motion():
                nonlocal x,y
                ship.move.left(1)
                ship1.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            x = root.winfo_screenwidth()//3+25
            y = 0
            def motion():
                nonlocal x,y
                ship.move.left(1)
                ship1.move.left(1)
                ship2.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            ship.move.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//3
            y = 0
            def motion():
                nonlocal x,y
                ship1.move.left(1)
                ship2.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            ship1.move.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//3
            y = 0
            def motion():
                nonlocal x,y
                ship2.move.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion)
            motion()
            ship2.move.right(root.winfo_screenwidth()+25)
        random.choice([f1,f2,f3])()
Thread(target=game_thread).start()
def jump(event):
    def jp():
        root.unbind('<Up>')
        personage.act.jump(100)
        root.bind('<Up>',jump)
    Thread(target=jp).start()
root.bind('<Up>',jump)
root.mainloop()

Понял, что это из-за update. Выводит на экран странные пути. (Что-то вроде \x15/\x270/\x134/\x150)
0
Programming
Эксперт
39485 / 9562 / 3019
Регистрация: 12.04.2006
Сообщений: 41,671
Блог
02.11.2019, 12:11
Ответы с готовыми решениями:

Странная задержка после update в QFrame
Господа, занялся я тут одной работой &quot;своеобразной&quot;, переписываю программу картографии на С++ Qt. Карту читаю гисовскую(подробности...

RecursionError
Здравствуйте, тему с подобным названием нашёл, прочёл решение для себя не понял( , как я понял с перевода ошибки Python проверил условие...

Ошибка RecursionError
Я на Pydroid3 написал программу при запуске выводится ошибка RecursionError Вот её текст: Traceback (most recent call last): File...

38
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 10:10  [ТС]
Студворк — интернет-сервис помощи студентам
Спасибо, попробую!

Добавлено через 5 минут
tooru, это не помогло!
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 10:24
Цитата Сообщение от Hyppoprogramm Посмотреть сообщение
это не помогло!
Да нет, помогло, просто там дальше ошибки появляются, уберите вложенные классы, сделайте просто, как в примере
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 10:32  [ТС]
Ок!

Добавлено через 6 минут
Убрал всё лишнее, ошибка остаётся.
Код
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from tkinter import *
#import time
#from threading import Thread
import random
class Kolobok():
    def __init__(self):
        self.img = PhotoImage(file='imgs/kolobok.gif')
        self.x = 30
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def jump(self,px,timeout_up=500,timeout_down=100):
        x = 0
        def up():
            self.y -= 1
            canvas.move(self.sprite,0,-1)
            canvas.update()
            x += 1
            if x < px:
                root.after(timeout_up,up)
        x = 0
        def down():
            self.y += 1
            canvas.move(self.sprite,0,1)
            canvas.update()
            x += 1
            if x < px:
                root.after(timeout_down,down)
class Ship():
    def __init__(self):
        self.img = PhotoImage(file='imgs/ship.gif')
        self.x = root.winfo_screenwidth() + 25
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def right(self,px):
        self.x += px
        canvas.move(self.sprite,px,0)
        canvas.update()
    def left(self,px):
        self.x -= px
        canvas.move(self.sprite,-px,0)
        canvas.update()
root = Tk()
root.attributes('-fullscreen',True)
canvas = Canvas(bg='white')
canvas.pack(expand=True,fill='both')
canvas.create_rectangle(0,0,root.winfo_screenwidth(),root.winfo_screenheight(),outline='#00a2e8',fill='#00a2e8')
canvas.create_rectangle(0,root.winfo_screenheight()-30,root.winfo_screenwidth(),root.winfo_screenheight(),outline='green',fill='green')
ship = Ship()
ship1 = Ship()
ship2 = Ship()
personage = Kolobok()
def game_thread():
    while True:
        def f1():
            x = root.winfo_screenwidth()+25
            y = 0
            def motion1():
                nonlocal x,y
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion1)
            motion1()
            ship.right(root.winfo_screenwidth()+25)
        def f2():
            x = root.winfo_screenwidth()//4
            y = 0
            def motion2():
                nonlocal x,y
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion2)
            motion2()
            x = root.winfo_screenwidth()-(root.winfo_screenwidth()//4)+25
            y = 0
            def motion3():
                nonlocal x,y
                ship1.left(1)
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion3)
            motion3()
            ship.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//4
            y = 0
            def motion4():
                nonlocal x,y
                ship1.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion4)
            motion4()
            ship1.right(root.winfo_screenwidth()+25)
        def f3():
            x = root.winfo_screenwidth()//3
            y = 0
            def motion5():
                nonlocal x,y
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion5)
            motion5()
            x = root.winfo_screenwidth()//3
            y = 0
            def motion6():
                nonlocal x,y
                ship.left(1)
                ship1.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion6)
            motion6()
            x = root.winfo_screenwidth()//3+25
            y = 0
            def motion7():
                nonlocal x,y
                ship.left(1)
                ship1.left(1)
                ship2.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion7)
            motion7()
            ship.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//3
            y = 0
            def motion8():
                nonlocal x,y
                ship1.left(1)
                ship2.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion8)
            motion8()
            ship1.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//3
            y = 0
            def motion9():
                nonlocal x,y
                ship2.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion9)
            motion9()
            ship2.right(root.winfo_screenwidth()+25)
        random.choice([f1,f2,f3])()
def jump(event):
    root.unbind('<Up>')
    personage.jump(100)
    root.bind('<Up>',jump)
root.bind('<Up>',jump)
root.update()
root.update_idletasks()
game_thread()
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 10:54
Вот немного поправил

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from tkinter import *
#import time
#from threading import Thread
import random
class Kolobok():
    def __init__(self):
        self.img = PhotoImage(file='imgs/kolobok.gif')
        self.x = 30
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def jump(self,px,timeout_up=500,timeout_down=100):
        x = 0
        def up():
            # nonlocal x
            self.y -= 1
            canvas.move(self.sprite,0,-self.y)
            # canvas.update()
            # x += 1
            # if x < px:
                # root.after(timeout_up,up)
        x = 0
        def down():
            self.y += 1
            canvas.move(self.sprite,0,1)
            # canvas.update()
            x += 1
            if x < px:
                root.after(timeout_down,down)
        return up
class Ship():
    def __init__(self):
        self.img = PhotoImage(file='imgs/ship.gif')
        self.x = root.winfo_screenwidth() + 25
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def right(self,px):
        self.x += px
        canvas.move(self.sprite,px,0)
        # canvas.update()
    def left(self,px):
        self.x -= px
        canvas.move(self.sprite,-px,0)
        # canvas.update()
root = Tk()
root.attributes('-fullscreen',True)
canvas = Canvas(bg='white')
canvas.pack(expand=True,fill='both')
canvas.create_rectangle(0,0,root.winfo_screenwidth(),root.winfo_screenheight(),outline='#00a2e8',fill='#00a2e8')
canvas.create_rectangle(0,root.winfo_screenheight()-30,root.winfo_screenwidth(),root.winfo_screenheight(),outline='green',fill='green')
ship = Ship()
ship1 = Ship()
ship2 = Ship()
personage = Kolobok()
def game_thread():
    # while True:
        def f1():
            x = root.winfo_screenwidth()+25
            y = 0
            def motion1():
                nonlocal x,y
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion1)
            motion1()
            ship.right(root.winfo_screenwidth()+25)
        def f2():
            x = root.winfo_screenwidth()//4
            y = 0
            def motion2():
                nonlocal x,y
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion2)
            motion2()
            x = root.winfo_screenwidth()-(root.winfo_screenwidth()//4)+25
            y = 0
            def motion3():
                nonlocal x,y
                ship1.left(1)
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion3)
            motion3()
            ship.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//4
            y = 0
            def motion4():
                nonlocal x,y
                ship1.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion4)
            motion4()
            ship1.right(root.winfo_screenwidth()+25)
        def f3():
            x = root.winfo_screenwidth()//3
            y = 0
            def motion5():
                nonlocal x,y
                ship.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion5)
            motion5()
            x = root.winfo_screenwidth()//3
            y = 0
            def motion6():
                nonlocal x,y
                ship.left(1)
                ship1.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion6)
            motion6()
            x = root.winfo_screenwidth()//3+25
            y = 0
            def motion7():
                nonlocal x,y
                ship.left(1)
                ship1.left(1)
                ship2.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion7)
            motion7()
            ship.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//3
            y = 0
            def motion8():
                nonlocal x,y
                ship1.left(1)
                ship2.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion8)
            motion8()
            ship1.right(root.winfo_screenwidth()+25)
            x = root.winfo_screenwidth()//3
            y = 0
            def motion9():
                nonlocal x,y
                ship2.left(1)
                ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
                ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
                if personage.x in ships_x and personage.y in ships_y:
                    pass
                y += 1
                if y < x:
                    root.after(750,motion9)
            motion9()
            ship2.right(root.winfo_screenwidth()+25)
        random.choice([f1,f2,f3])()
def jump(event):
    # root.unbind('<Up>')
    personage.jump(100)()
    # root.bind('<Up>',jump)
root.bind('<Up>',jump)
while True:
    root.update()
    root.update_idletasks()
    game_thread()
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 11:02  [ТС]
Теперь выдаёт очень много вот таких ошибок:
Code
1
2
3
4
    while executing
"(какое-то восьмизначное число)motion(какое-то однозначное число)"
    ("after" script)
invalid command name "(какое-то восьмизначное число)motion(какое-то однозначное число)"
А в конце tcl error.
Насколько я понял, это tcl ошибка, связанная с функциями motion.
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 11:16
Цитата Сообщение от Hyppoprogramm Посмотреть сообщение
Теперь выдаёт очень много вот таких ошибок:
Эти ошибки при выходе, из-за root.after, он еще продолжает работу после закрытия окна
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 11:25  [ТС]
А понял! Но без update шипов не видно.

Добавлено через 11 секунд
А с update ошибка.
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 11:36
Цитата Сообщение от Hyppoprogramm Посмотреть сообщение
Но без update шипов не видно.
Нет шипи с update не связаны, вот, если убрать все из функции game_thread

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from tkinter import *
#import time
#from threading import Thread
import random
class Kolobok():
    def __init__(self):
        self.img = PhotoImage(file='imgs/kolobok.gif')
        self.x = 30
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def jump(self,px,timeout_up=500,timeout_down=100):
        x = px
        def up():
            nonlocal x
            self.y -= 1
            canvas.move(self.sprite,0,-x)
            # canvas.update()
            x += 1
            # if x < px:
                # root.after(timeout_up,up)
        # x = 0
        def down():
            self.y += 1
            canvas.move(self.sprite,0,1)
            # canvas.update()
            x += 1
            if x < px:
                root.after(timeout_down,down)
        return up
class Ship():
    def __init__(self):
        self.img = PhotoImage(file='imgs/ship.gif')
        self.x = root.winfo_screenwidth() - 25
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def right(self,px):
        self.x += px
        canvas.move(self.sprite,px,0)
        # canvas.update()
    def left(self,px):
        self.x -= px
        canvas.move(self.sprite,-px,0)
        # canvas.update()
root = Tk()
root.attributes('-fullscreen',True)
canvas = Canvas(bg='white')
canvas.focus()
canvas.pack(expand=True,fill='both')
canvas.create_rectangle(0,0,root.winfo_screenwidth(),root.winfo_screenheight(),outline='#00a2e8',fill='#00a2e8')
canvas.create_rectangle(0,root.winfo_screenheight()-30,root.winfo_screenwidth(),root.winfo_screenheight(),outline='green',fill='green')
ship = Ship()
# ship1 = Ship()
# ship2 = Ship()
personage = Kolobok()
def game_thread():
    # while True:
     ship.left(1)
        # def f1():
        #     x = root.winfo_screenwidth()+25
        #     y = 0
        #     def motion1():
        #         nonlocal x,y
        #         ship.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion1)
        #     motion1()
        #     ship.right(root.winfo_screenwidth()+25)
        # def f2():
        #     x = root.winfo_screenwidth()//4
        #     y = 0
        #     def motion2():
        #         nonlocal x,y
        #         ship.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion2)
        #     motion2()
        #     x = root.winfo_screenwidth()-(root.winfo_screenwidth()//4)+25
        #     y = 0
        #     def motion3():
        #         nonlocal x,y
        #         ship1.left(1)
        #         ship.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion3)
        #     motion3()
        #     ship.right(root.winfo_screenwidth()+25)
        #     x = root.winfo_screenwidth()//4
        #     y = 0
        #     def motion4():
        #         nonlocal x,y
        #         ship1.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion4)
        #     motion4()
        #     ship1.right(root.winfo_screenwidth()+25)
        # def f3():
        #     x = root.winfo_screenwidth()//3
        #     y = 0
        #     def motion5():
        #         nonlocal x,y
        #         ship.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion5)
        #     motion5()
        #     x = root.winfo_screenwidth()//3
        #     y = 0
        #     def motion6():
        #         nonlocal x,y
        #         ship.left(1)
        #         ship1.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion6)
        #     motion6()
        #     x = root.winfo_screenwidth()//3+25
        #     y = 0
        #     def motion7():
        #         nonlocal x,y
        #         ship.left(1)
        #         ship1.left(1)
        #         ship2.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion7)
        #     motion7()
        #     ship.right(root.winfo_screenwidth()+25)
        #     x = root.winfo_screenwidth()//3
        #     y = 0
        #     def motion8():
        #         nonlocal x,y
        #         ship1.left(1)
        #         ship2.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion8)
        #     motion8()
        #     ship1.right(root.winfo_screenwidth()+25)
        #     x = root.winfo_screenwidth()//3
        #     y = 0
        #     def motion9():
        #         nonlocal x,y
        #         ship2.left(1)
        #         ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #         ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #         if personage.x in ships_x and personage.y in ships_y:
        #             pass
        #         y += 1
        #         if y < x:
        #             root.after(750,motion9)
        #     motion9()
        #     ship2.right(root.winfo_screenwidth()+25)
        # random.choice([f1,f2,f3])()
def jump(event):
    # root.unbind('<Up>')
    personage.jump(1)()
    # root.bind('<Up>',jump)
root.bind('<Up>', jump)
while True:
    root.update()
    root.update_idletasks()
    game_thread()
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 11:44  [ТС]
Теперь вместа прыжка колобок только поднимается вверх на 1 пиксель.
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 11:52
Цитата Сообщение от Hyppoprogramm Посмотреть сообщение
Теперь вместа прыжка колобок только поднимается вверх на 1 пиксель.
В образце, который я выложил, есть прыжок
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 12:03  [ТС]
Теперь проблема в том, что прыжок останавливает шип.
Код
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
from tkinter import *
#import time
#from threading import Thread
import random
class Kolobok():
    def __init__(self):
        self.img = PhotoImage(file='imgs/kolobok.gif')
        self.x = 30
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def up(self,px):
        canvas.move(self.sprite,0,-1)
    def down(self,px):
        canvas.move(self.sprite,0,1)
class Ship():
    def __init__(self):
        self.img = PhotoImage(file='imgs/ship.gif')
        self.x = root.winfo_screenwidth() - 25
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def right(self,px):
        self.x += px
        canvas.move(self.sprite,px,0)
        # canvas.update()
    def left(self,px):
        self.x -= px
        canvas.move(self.sprite,-px,0)
        # canvas.update()
root = Tk()
root.attributes('-fullscreen',True)
canvas = Canvas(bg='white')
canvas.focus()
canvas.pack(expand=True,fill='both')
canvas.create_rectangle(0,0,root.winfo_screenwidth(),root.winfo_screenheight(),outline='#00a2e8',fill='#00a2e8')
canvas.create_rectangle(0,root.winfo_screenheight()-30,root.winfo_screenwidth(),root.winfo_screenheight(),outline='green',fill='green')
ship = Ship()
# ship1 = Ship()
# ship2 = Ship()
personage = Kolobok()
def game_thread():
    # while True:
     ship.left(1)
        # def f1():
        #    x = root.winfo_screenwidth()+25
        #    y = 0
        #    def motion1():
        #        nonlocal x,y
        #        ship.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion1)
        #    motion1()
        #    ship.right(root.winfo_screenwidth()+25)
        # def f2():
        #    x = root.winfo_screenwidth()//4
        #    y = 0
        #    def motion2():
        #        nonlocal x,y
        #        ship.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion2)
        #    motion2()
        #    x = root.winfo_screenwidth()-(root.winfo_screenwidth()//4)+25
        #    y = 0
        #    def motion3():
        #        nonlocal x,y
        #        ship1.left(1)
        #        ship.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion3)
        #    motion3()
        #    ship.right(root.winfo_screenwidth()+25)
        #    x = root.winfo_screenwidth()//4
        #    y = 0
        #    def motion4():
        #        nonlocal x,y
        #        ship1.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion4)
        #    motion4()
        #    ship1.right(root.winfo_screenwidth()+25)
        # def f3():
        #    x = root.winfo_screenwidth()//3
        #    y = 0
        #    def motion5():
        #        nonlocal x,y
        #        ship.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion5)
        #    motion5()
        #    x = root.winfo_screenwidth()//3
        #    y = 0
        #    def motion6():
        #        nonlocal x,y
        #        ship.left(1)
        #        ship1.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion6)
        #    motion6()
        #    x = root.winfo_screenwidth()//3+25
        #    y = 0
        #    def motion7():
        #        nonlocal x,y
        #        ship.left(1)
        #        ship1.left(1)
        #        ship2.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion7)
        #    motion7()
        #    ship.right(root.winfo_screenwidth()+25)
        #    x = root.winfo_screenwidth()//3
        #    y = 0
        #    def motion8():
        #        nonlocal x,y
        #        ship1.left(1)
        #        ship2.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion8)
        #    motion8()
        #    ship1.right(root.winfo_screenwidth()+25)
        #    x = root.winfo_screenwidth()//3
        #    y = 0
        #    def motion9():
        #        nonlocal x,y
        #        ship2.left(1)
        #        ships_x = list(range(ship.x-25,ship.x+25)) + list(range(ship1.x-25,ship1.x+25)) + list(range(ship2.x-25,ship2.x+25))
        #        ships_y = list(range(ship.y-25,ship.y+25)) + list(range(ship1.y-25,ship1.y+25)) + list(range(ship2.y-25,ship2.y+25))
        #        if personage.x in ships_x and personage.y in ships_y:
        #            pass
        #        y += 1
        #        if y < x:
        #            root.after(750,motion9)
        #    motion9()
        #    ship2.right(root.winfo_screenwidth()+25)
        # random.choice([f1,f2,f3])()
def jump(event):
    root.unbind('<Up>')
    for i in range(100):
        personage.up(1)
        root.update()
        root.update_idletasks()
    for i in range(100):
        personage.down(1)
        root.update()
        root.update_idletasks()
    root.bind('<Up>',jump)
root.bind('<Up>', jump)
while True:
    for i in range(root.winfo_screenwidth()+25):
        root.update()
        root.update_idletasks()
        game_thread()
    ship.right(root.winfo_screenwidth()+25)
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 12:13
Уберите root.update() и root.update_idletasks() из функции jump
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 12:23  [ТС]
Убрал, но теперь не видно как колобок прыгает.
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
05.11.2019, 12:31
Так потому, что там нет сейчас нормального прыжка, сделайте прыжок, поднимается сначала движется вверх, потом движется вниз
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
05.11.2019, 12:43  [ТС]
Но тогда можно будеть "летать", а мне этого не надо.
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
06.11.2019, 00:16
Цитата Сообщение от Hyppoprogramm Посмотреть сообщение
Но тогда можно будеть "летать", а мне этого не надо.
Надо добавить проверку, в прыжке или нет
1
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
06.11.2019, 14:51  [ТС]
Теперь если зажать клавишу Up игрок может парить и ещё прыжок происходит слишком быстро (надо чтобы он взлетал постепенно.)
Функция прыжка:
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
jump_ = False
def jump(event):
    global jump_
    if jump_ == False:
        jump_ = True
        for i in range(100):
            personage.up(1)
def jump_stop(event):
    global jump_
    for i in range(100):
        personage.down(1)
    jump_ = False
canvas.bind_all("<KeyPress-Up>", jump)
canvas.bind_all("<KeyRelease-Up>", jump_stop)
0
1293 / 677 / 367
Регистрация: 07.01.2019
Сообщений: 2,302
06.11.2019, 23:31
Вот пример прыгающего игрока

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from tkinter import *
from functools import partial
 
root = Tk()
 
c = Canvas(root, width=800, height=600, bg='white')
c.focus()
c.pack()
 
class Player:
    def __init__(self, c):
        self.c = c
        self.x = 50
        self.y = 510
        self.sprite = c.create_oval(self.x, self.y, self.x + 20, self.y + 20, width=2)
        self.jump = False
        self.left = False
        self.right = False
        self.imp = 0
        self.grav = 0.1
 
    def move(self):
        if self.jump:
            self.imp -= self.grav
            self.c.move(self.sprite,0,-self.imp)
            if self.imp <= -5:
                self.jump = False
                self.c.coords(self.sprite,self.x, 510, self.x + 20, 510 + 20)
        else:
            if self.left:
                self.x -= 2
                self.c.move(self.sprite, -2, 0)
            if self.right:
                self.x += 2
                self.c.move(self.sprite, 2, 0)
 
 
    def left_move(self, bl):
        self.left = bl
 
    def right_move(self, bl):
        self.right = bl
 
    def jump_move(self):
        if self.jump == False:
            self.jump = True
            self.imp = 5
 
player = Player(c)
    
root.bind('<Up>', lambda ev: player.jump_move())
root.bind('<Left>', lambda ev: player.left_move(True))
root.bind('<KeyRelease-Left>', lambda ev: player.left_move(False))
root.bind('<Right>', lambda ev: player.right_move(True))
root.bind('<KeyRelease-Right>', lambda ev: player.right_move(False))
 
while True:
    root.update()
    root.update_idletasks()
    player.move()
    root.after(5)
0
 Аватар для GulgDev
132 / 118 / 29
Регистрация: 09.07.2019
Сообщений: 1,071
09.11.2019, 08:35  [ТС]
tooru, спасибо огромное! Всё сделал. Работает!
Файл Игра.pyw
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from tkinter import *
from tkinter import messagebox
import pickle
num = 0
try:
    open('record','rb')
except:
    f = open('record','wb')
    f.write(pickle.dumps([0,'']))
    f.close()
f = open('record','rb')
record = pickle.loads(f.read())
record[0] = int(record[0])
f.close()
root = Tk()
root.withdraw()
root.update()
a = messagebox.askyesno('Начать игру?','Правила: Вы должны перепрыгивать шипы встречающиеся у вас на пути. Чтобы прыгнуть Вам надо нажать стрелку вверх.\nНачать игру?')
if not a:
    quit()
else:
    root.destroy()
class Kolobok():
    def __init__(self):
        self.img = PhotoImage(file='imgs/kolobok.gif')
        self.x = 30
        self.y = root.winfo_screenheight() - 55
        self.start_x = self.x
        self.start_y = self.y
        self.max_y = self.y - 50
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
        self.jump = False
        self.i = 1
    def up(self,px):
        personage.y -= 1
        canvas.move(self.sprite,0,-1)
    def down(self,px):
        personage.y += 1
        canvas.move(self.sprite,0,1)
    def move(self):
        if self.jump:
            def down():
                personage.y += 50
                canvas.move(self.sprite,0,50)
            personage.y -= 50
            canvas.move(self.sprite,0,-50)
            root.after(500,down)
            root.after(50)
            self.jump = False
    def jump_move(self,event):
        if self.jump == False:
            self.jump = True
            self.move()
class Ship():
    def __init__(self):
        self.img = PhotoImage(file='imgs/ship.gif')
        self.x = root.winfo_screenwidth() - 25
        self.y = root.winfo_screenheight() - 55
        self.sprite = canvas.create_image(self.x,self.y,image=self.img)
    def right(self,px):
        self.x += px
        canvas.move(self.sprite,px,0)
    def left(self,px):
        self.x -= px
        canvas.move(self.sprite,-px,0)
root = Tk()
root.focus_force()
root.attributes('-fullscreen',True)
canvas = Canvas(bg='white')
canvas.focus()
canvas.pack(expand=True,fill='both')
canvas.create_rectangle(0,0,root.winfo_screenwidth(),root.winfo_screenheight(),outline='#00a2e8',fill='#00a2e8')
canvas.create_rectangle(0,root.winfo_screenheight()-30,root.winfo_screenwidth(),root.winfo_screenheight(),outline='green',fill='green')
ship = Ship()
personage = Kolobok()
def game_thread():
    ship.left(1)
root.bind("<Up>", personage.jump_move)
num = 0
ok = True
while ok:
    for i in range(root.winfo_screenwidth()+25):
        root.update()
        root.update_idletasks()
        game_thread()
        if personage.y > personage.max_y:
            canvas.coords(personage.sprite,personage.start_x,personage.start_y)
        if personage.y - 25 >= ship.y-25 and personage.x -25 >= ship.x-25:
            ok = False
            break
    num += 1
    ship.right(root.winfo_screenwidth()+25)
num -= 1
def end_game():
    if num > record[0]:
        mb_plus = ' Старый рекорд: ' + str(record[0]) + ' (Игрок: ' + record[1] + ')\nНовый рекорд!'
        f = open('record','wb')
        f.write(pickle.dumps([num,name]))
        f.close()
    else:
        mb_plus = ' Рекорд: ' + str(record[0]) + ' (Игрок: ' + record[1] + ')'
    messagebox.showinfo('Конец игры','Вы проиграли. Ваши очки: ' + str(num) + mb_plus)
    quit()
root.destroy()
root = Tk()
root.withdraw()
root.update()
get_name = Toplevel()
get_name.focus_force()
get_name.title('Введите имя')
get_name.geometry('200x150')
get_name.attributes('-topmost',True)
get_name.resizable(False,False)
entry = Entry(get_name)
entry.pack()
def end_get_name(event):
    global name
    name = entry.get()
    if len(name) == 0:
        dont_close()
    else:
        ok = False
        get_name.destroy()
        end_game()
def dont_close():
    get_name.geometry('210x160')
    get_name.update()
    get_name.geometry('200x150')
get_name.bind('<Return>',end_get_name)
get_name.protocol('WM_DELETE_WINDOW',dont_close)
get_name.mainloop()
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
inter-admin
Эксперт
29715 / 6470 / 2152
Регистрация: 06.03.2009
Сообщений: 28,500
Блог
09.11.2019, 08:35
Помогаю со студенческими работами здесь

RecursionError: maximum recursion depth exceeded
RecursionError: maximum recursion depth exceeded выводит при попытке запустить файл, подскажите где ошибка заранее благодарен вот сам...

RecursionError: maximum recursion depth exceeded in comparison
Всем добрый вечер Возникли проблемы с задачей. Условие: Найдите аналитическое выражение для {p}_{3}(n) Вход программы состоит...

[Sympy] RecursionError: maximum recursion depth exceeded
Второй час уже сижу, пытаюсь понять где я допустил ошибку... Может у кого-то это выйдет намного лучше чем у меня, если да, то буду...

RecursionError: maximum recursion depth exceeded in comparison
def F(n): if n &lt;= 5: return n if n &gt; 5 and n % 5 == 0: return n+F(n / 5 + 1) if n&gt;5 and n % 5 != 0: ...

Странная(или не странная, незнаю) реакция на буквы, знаки операций
Всем добрый день. Делаю маленькую наработку, пока есть только начало. Ниже код: #include &lt;iostream&gt; #include...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
39
Ответ Создать тему
Новые блоги и статьи
Отправка уведомления на почту при изменении наименования справочника
Maks 24.03.2026
Программная отправка письма электронной почты на примере изменения наименования типового справочника "Склады" в конфигурации БП3. Перед реализацией необходимо выполнить настройку системной учетной. . .
модель ЗдравоСохранения 5. Меньше увольнений- больше дохода!
anaschu 24.03.2026
Теперь система здравосохранения уменьшает количество увольнений. 9TO2GP2bpX4 a42b81fb172ffc12ca589c7898261ccb/ https:/ / rutube. ru/ video/ a42b81fb172ffc12ca589c7898261ccb/ Слева синяя линия -. . .
Midnight Chicago Blues
kumehtar 24.03.2026
Такой Midnight Chicago Blues, знаешь?. . Когда вечерние улицы становятся ночными, а ты не можешь уснуть. Ты идёшь в любимый старый бар, и бармен наливает тебе виски. Ты смотришь на пролетающие. . .
Контроль уникальности заводского номера - вариант №2
Maks 24.03.2026
В отличие от предыдущего варианта добавлено прерывание циклов, также добавлены новые переменные для сохранения контекста ошибки перед прерыванием цикла: Процедура ПередЗаписью(Отказ, РежимЗаписи,. . .
SDL3 для Desktop (MinGW): Вывод текста со шрифтом TTF с помощью библиотеки SDL3_ttf на Си и C++
8Observer8 24.03.2026
Содержание блога Финальные проекты на Си и на C++: finish-text-sdl3-c. zip finish-text-sdl3-cpp. zip
Жизнь в неопределённости
kumehtar 23.03.2026
Жизнь — это постоянное существование в неопределённости. Например, даже если у тебя есть список дел, невозможно дойти до точки, где всё окончательно завершено и больше ничего не осталось. В принципе,. . .
Модель здравоСохранения: работники работают быстрее после её введения.
anaschu 23.03.2026
geJalZw1fLo Корпорация до введения программа здравоохранения имела много невыполненных работниками заданий, после введения программы количество заданий выросло. Но на выплатах по больничным это. . .
Контроль уникальности заводского номера - вариант №1
Maks 23.03.2026
Алгоритм контроля уникальности заводского (или серийного) номера на примере нетипового документа выдачи шин для спецтехники с табличной частью, разработанного в конфигурации КА2. Данные берутся из. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru