IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GUI Python Discussion :

[pygame] Supprimer ligne colonne


Sujet :

GUI Python

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Février 2003
    Messages
    926
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2003
    Messages : 926
    Points : 273
    Points
    273
    Par défaut [pygame] Supprimer ligne colonne
    Avec pygame, j'ai une grille de 50X50 cases. Pourriez-vous me dire comment on fait pour supprimer une ligne ou une colonne, svp?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    import pygame
     
    # Define some colors
    BLACK = (0, 0, 0)
    WHITE = (255, 255, 255)
    GREEN = (0, 255, 0)
    RED = (255, 0, 0)
     
    # This sets the WIDTH and HEIGHT of each grid location
    WIDTH = 27
    HEIGHT = 15
     
    # This sets the margin between each cell
    MARGIN = 1
     
    # Create a 2 dimensional array. A two dimensional
    # array is simply a list of lists.
    grid = []
    for row in range(50):
        # Add an empty array that will hold each cell
        # in this row
        grid.append([])
        for column in range(50):
            grid[row].append(0)  # Append a cell
     
    # Set row 1, cell 5 to one. (Remember rows and
    # column numbers start at zero.)
    grid[16][15] = 1
     
    # Initialize pygame
    pygame.init()
     
    # Set the HEIGHT and WIDTH of the screen
    WINDOW_SIZE = [1500, 855]
    screen = pygame.display.set_mode(WINDOW_SIZE)
     
    # Set title of screen
    pygame.display.set_caption("Array Backed Grid")
     
    # Loop until the user clicks the close button.
    done = False
     
    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()
     
    # -------- Main Program Loop -----------
    while not done:
        for event in pygame.event.get():  # User did something
            if event.type == pygame.QUIT:  # If user clicked close
                done = True  # Flag that we are done so we exit this loop
            elif event.type == pygame.MOUSEBUTTONDOWN:
                # User clicks the mouse. Get the position
                pos = pygame.mouse.get_pos()
                # Change the x/y screen coordinates to grid coordinates
                column = pos[0] // (WIDTH + MARGIN)
                row = pos[1] // (HEIGHT + MARGIN)
                # Set that location to one
     
                if grid[row][column] == 1:
                    grid[row][column] = 0
                else:
                    grid[row][column] = 1
     
     
                print("Click ", pos, "Grid coordinates: ", row, column)
     
        # Set the screen background
        screen.fill(BLACK)
     
        # Draw the grid
        for row in range(50):
            for column in range(50):            
                color = WHITE            
                if grid[row][column] == 1:               
                    color = GREEN
                pygame.draw.rect(screen,
                                 color,
                                 [(MARGIN + WIDTH) * column + MARGIN,
                                  (MARGIN + HEIGHT) * row + MARGIN,
                                  WIDTH,
                                  HEIGHT])
     
        # Limit to 60 frames per second
        clock.tick(60)
     
        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()
     
    # Be IDLE friendly. If you forget this line, the program will 'hang'
    # on exit.
    pygame.quit()

  2. #2
    Membre confirmé

    Homme Profil pro
    Bidouilleur
    Inscrit en
    Avril 2016
    Messages
    721
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Bidouilleur

    Informations forums :
    Inscription : Avril 2016
    Messages : 721
    Points : 503
    Points
    503
    Billets dans le blog
    1
    Par défaut
    Salut !

    Ce script affiche dans ton terminal le numéro de la ligne et colonne où le clic a été fait, partant de ça, il est facile de supprimer dans la grille à afficher cette ligne et cette colonne, ce n'est rien d'autre qu'un travail sur une liste.

    Tu devrais déjà commencer par essayer d'afficher la ligne et colonne en vert, et surtout réduire pour tes tests à un tableau plus petit, 5x5 par exemple.

    Et quand t'auras réussi ça, tu pourras commencer le travail de la suppression et des décalages (ou redimensionnements) des autres cases.

    Et quand tout sera fonctionnel, il faudra encore faire des modifications pour les performances, parce qu'en l'état ça pompe énormément de ressources processeur pour rien.
    Le temps ronge l'amour comme l'acide.

Discussions similaires

  1. Supprimer ligne et colonne d'une matrice
    Par programeur dans le forum Débuter
    Réponses: 2
    Dernier message: 06/03/2013, 15h51
  2. [XL-2000] Supprimer ligne si cellule d'une colonne = 0, sur une plage de cellules
    Par audesara dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 04/05/2011, 16h16
  3. Réponses: 9
    Dernier message: 17/02/2009, 18h48
  4. Réponses: 4
    Dernier message: 24/09/2008, 01h00
  5. Supprimer lignes en fonction d'une colonne
    Par eillon dans le forum Macros et VBA Excel
    Réponses: 12
    Dernier message: 10/12/2007, 11h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo