Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy is my code still displaying the old panes?
    primarykey
    data
    text
    <p>So basically I have a two separate screens that I want displayed. One that has 11 Panes displayed on the screen at one time and once I click on a Pane named keyboard it should clear the screen and set up 36 Panes which should display a keyboard (for test purposes I only used three panes).</p> <p>My problem is that once I click on keyboard it does clear the screen and display the 3 test panes how it also display's my other 10 panes that come from the first page.</p> <p><strong>Example:</strong> This is fine to start with: <img src="https://i.stack.imgur.com/5ciSM.png" alt="Fine Display"></p> <p>This is not fine. (A, B And C should be displayed but the rest shouldn't): <img src="https://i.stack.imgur.com/Oi3Pb.png" alt="Not Fine"></p> <p>Here is the code:</p> <pre><code>import pygame import sys white = (255,255,255) black = (0,0,0) objs = [] MAIN_BUTTON = 2 KEYBOARD = True WORDS = False class Pane(): def __init__(self, textToDisplay, coordinates, screen): self.textToDisplay = textToDisplay self.coordinates = coordinates self.screen = screen self.font = pygame.font.SysFont('Palace Script MT', 25) Screen = pygame.display.set_mode((1366,768), 0, 32) self.screen = Screen self.screen.fill((white)) def coordinates(self): return self.coordinates def text(self): return self.textToDisplay def drawPane(self): textCoords = self.coordinates self.screen.blit(self.font.render(self.textToDisplay, True, (black)), textCoords) pygame.draw.rect(self.screen, (black), self.coordinates, 2) pygame.display.update() class Screen(): NoOfPanes = 0 Panes = [] paneLocs = [(583, 334, 300, 150), (633, 150, 200, 125), (633, 600, 200, 125), (350, 360, 200, 100), (925, 360, 200, 100), (1000, 150, 150, 100), (275, 150, 150, 100), (275, 600, 150, 100), (1000, 600, 150, 100), (75, 350, 200, 100), (0, 668, 200, 100) ] keyboardPaneLocs = [(0, 100, 100, 100), (0, 200, 100, 100), (0, 300, 100, 100), (0, 400, 100, 100) ] def __init__(self): pygame.init() pygame.display.set_caption('Box Test') self.font = pygame.font.SysFont('Arial', 25) Screen = pygame.display.set_mode((1366,768), 0, 32) self.screen = Screen self.screen.fill((white)) pygame.display.update() def addPane(self, textToDisplay, keyboardFlag): if (not keyboardFlag) and (self.NoOfPanes &gt; 11): print("Limit Reached") else: print(int(self.NoOfPanes)) if keyboardFlag: newPane = Pane(textToDisplay, self.keyboardPaneLocs[self.NoOfPanes], Screen) else: newPane = Pane(textToDisplay, self.paneLocs[self.NoOfPanes], Screen) self.Panes.append(newPane) self.NoOfPanes = self.NoOfPanes + 1 pygame.display.update() def drawPanes(self): for Pane in self.Panes: Pane.drawPane() def mousePosition(self): global clickPos global releasePos for event in pygame.event.get(): if event.type == MAIN_BUTTON: self.Pos = pygame.mouse.get_pos() return MAIN_BUTTON else: return False def mouseDown(self, posx, posy): textToReturn = "Nothing selected" for Pane in self.Panes: paneCoords = Pane.coordinates print(str(paneCoords[0]) + ":" + str(paneCoords[1]) + ":" + str(paneCoords[2]) + ":" + str(paneCoords[3])) if (paneCoords[0] &lt;= posx &lt;= paneCoords[0]+paneCoords[2]) and (paneCoords[1] &lt;= posy &lt;= paneCoords[1]+paneCoords[3]): textToReturn = Pane.text() return textToReturn def displayKeyboard(self): self.addPane("A", KEYBOARD) self.addPane("B", KEYBOARD) self.addPane("C", KEYBOARD) def clearScreen(self): Screen = pygame.display.set_mode((1366,768), 0, 32) self.screen = Screen self.screen.fill((white)) if __name__ == '__main__': myScreen = Screen() myScreen.addPane("1", WORDS) myScreen.addPane("2", WORDS) myScreen.addPane("3", WORDS) myScreen.addPane("4", WORDS) myScreen.addPane("5", WORDS) myScreen.addPane("6", WORDS) myScreen.addPane("7", WORDS) myScreen.addPane("8", WORDS) myScreen.addPane("9", WORDS) myScreen.addPane("10", WORDS) myScreen.addPane("Keyboard", WORDS) myScreen.drawPanes() while True: ev = pygame.event.get() for event in ev: if event.type == pygame.MOUSEBUTTONUP: posx,posy = pygame.mouse.get_pos() textSelected = myScreen.mouseDown(posx, posy) print(textSelected) if textSelected == "Keyboard": myScreen = Screen() myScreen.clearScreen() myScreen.displayKeyboard() myScreen.drawPanes() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit(); sys.exit(); </code></pre> <p>I think the problem that I am facing is that all of these panes are being added to the list <code>Panes = []</code>. How can I make sure that this list is clear before I display the new panes through the use of the function <code>def drawPanes(self):</code> </p> <p>Don't take my word for it as it is just an assumption and I am well and truly stuck. (Any help is appreciated.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload