A voir également:
- .move + events deplacement TKINTER python 3.7
- Historique déplacement google - Guide
- Citizen code python avis - Accueil - Outils
- Mouse move - Télécharger - Utilitaires
- Sports events 365 avis ✓ - Forum Microsoft Office
- Eteindre tpe move 5000 - Forum Matériel & Système
12 févr. 2020 à 16:23
desole je t'envoie mon code. Bon c'est pas minimaliste mais pour comprendre comment j'ai fais je t'envoie tout.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from tkinter import *
from time import sleep
import threading
def KeyBoard(event):
global xc,yc,LC
NewL,NewC=xc,yc
Key = event.keysym
if Key == 'Down':
NewL,NewC=xc,yc+1
if Key == 'Left':
NewL,NewC=xc-1,yc
if Key == 'Right':
NewL,NewC=xc+1,yc
Verification(NewL,NewC)
def Verification(NewL,NewC):
global xc,yc,LC
if LC[NewL][NewC]==0:
LC[xc][yc]=0
xc,yc=NewL,NewC
LC[xc][yc]=1
MyCanvas.coords(Piece,xc*20,yc*20 , xc*20 +20, yc*20 +20)
def chutelibre():
global xc,yc,LC
NewL,NewC=xc,yc
while temps<20:
b=b+1
if b>5000:
yc=yc+1
print(xc,yc)
MyCanvas.coords(Piece,xc*20,yc*20 , xc*20 +20, yc*20 +20)
break
def comptage():
global b
def chuteobjet():
global chutelibrecoord,yc,LC,NewL,NewC
NewL,NewC=chutelibrecoord,chutelibrecoord2
if MyCanvas.coords(Piece)[3]>675 or MyCanvas.coords(Piece)[3]<0 :
chutelibrecoord=0
MyCanvas.move(Piece,chutelibrecoord2,chutelibrecoord)
print(LC)
MyWindow.after(20,chuteobjet)
Verification(NewL,NewC)
###############################################################################
MyWindow = Tk()
MyWindow.title('Tetris')
###############################################################################
temps=0
b=0
t = threading.Thread(target=comptage)
chutelibrecoord=7
chutelibrecoord2=0
xc = 7
yc = 0
a=0
###############################################################################
MyCanvas = Canvas(MyWindow, width = 300, height =700, bg ='blue')
Piece = MyCanvas.create_rectangle(xc*20,yc*20,xc*20+20,yc*20+20,width=0,fill='red')
MyCanvas.focus_set()
MyCan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,0,0,0,0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
print(LC)
i=0
j=0
while j < 15:
while i<35:
if LC[j][i]==1:
MyCanvas.create_rectangle(j*20,i*20,j*20+20,i*20+20,fill='black')
i=i+1
i=0
j=j+1
comptage()
MyWindow.mainloop()
12 févr. 2020 à 19:23
Je ne vois pas à quoi sert le thread dans ton code
12 févr. 2020 à 20:03
le thread était seulement un test pr faire une pause au prog
mais dcp j’ai trouvé comment faire merci qd meme
12 févr. 2020 à 16:23
12 févr. 2020 à 16:24