Ouvrir une fenêtre python

Fermé
aboe45140 Messages postés 28 Date d'inscription lundi 4 décembre 2017 Statut Membre Dernière intervention 19 septembre 2021 - 19 janv. 2020 à 16:09
 trifou - 19 janv. 2020 à 18:19
Bonjour! J'ai finaliser un Algorithme python mais je l'ai fais sur le site https://trinket.io/ . Tout fonctionne mais lorsque je le démarre sur le logiciel python de mon ordi tout bug. Je pense que c'est parce qu'il n'y a pas de fenêtre et j'aimerais en créer une .

import turtle
myPen = turtle.Turtle()
myPen.speed(10)
myPen.color("#000000")

t = turtle #Je renomme la tortue "t"

t.penup()

t.goto(-150,180)

t.pendown()
#les 3 dernières instructions sont là pour que "t" se déplace en haut à gauche de la fenêtre

side=10 #la longueurs de chaque carrés 

t.color("green")

t.speed(10)

for n in range (25):#pour faire 25 carrés de longs
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)#dessiner un seul carré
  t.end_fill()
  t.forward(side)
  
t.penup()

t.goto(-150,170)#le curseur baisse d'une colonne et reviens ainsi à gauche

t.pendown

for n in range (25):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,160)

for n in range (11):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (11):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)

t.goto(-150,150)

for n in range (9):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (9):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,140)
  
for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (4):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (4):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,130)

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range(5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,120)

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (6):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("white")

for n in range(4):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range(3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (6):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,110)

for n in range (2):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)

t.color("yellow")

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range(4):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("white")

for n in range(2):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range (1):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (2):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,100)

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range(6):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range(6):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("white")

for n in range (1):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (6):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,90)

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
  
t.color("yellow")

for n in range (5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)

t.color("green")

for n in range(5):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,80)

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (4):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("blue")

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)

t.color("yellow")

for n in range (4):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)

t.color("green")

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,70)

for n in range (9):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (7):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (9):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,60)

for n in range (11):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("yellow")

for n in range (3):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.color("green")

for n in range (11):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,50)

for n in range (25):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
t.goto(-150,40)

for n in range (25):
  t.begin_fill()
  for i in range (4):
    t.forward(10)
    t.left(90)
  t.end_fill()
  t.forward(side)
  
A voir également:

1 réponse

Plus de 500 lignes de codes pour faire ce que l'on peut faire en 70 lignes :-/

Ton code ne bug pas, c'est simplement la fenêtre qui se ferme à la fin des opérations.
La page de la doc turtle de python fourni alors la réponse à ta question.
https://docs.python.org/fr/3/library/turtle.html#turtle.mainloop

Y a même un exemple de code basique au début de la page montrant l'utilisation de done.
0