How do I solve an attribute error?

2024/9/22 6:50:42

So like I said before my code (Or my current project that I am working on) is riddled with errors. So far I have at least solved a dozen errors or more and honestly I just give up. I mean God knows how many more there are.

The current problem that I am having is an AttributeError which is in my opinion one of the easiest errors to fix however I seem to have gone in to complete spaghetti mode and I have no clue on how to fix the problem.

{The error itself:

Traceback (most recent call last):File "C:\Users\Burak\Desktop\boxtrial.py", line 87, in <module>myScreen.addPane("1")File "C:\Users\Burak\Desktop\boxtrial.py", line 67, in addPanemyPane.drawPane()File "C:\Users\Burak\Desktop\boxtrial.py", line 19, in drawPaneself.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
AttributeError: 'Pane' object has no attribute 'Screen'

}

I will list the code below but I feel as if I should explain what I am trying to do so you have some sort of understanding of the code. Basically in the main loop I call upon the "Class Screen" which helps to create a PyGame screen that comes up once run. On that screen I am trying to get rectangles to appear on the screen in fixed positions (The coordinates are specific but the ones I use on the code are just for test purposes). I then have another class that is called "Pane" and this class is there so that I can draw many instances of the class pane within screen (If that makes sense).

If someone can help me get rid of the error that would be of grate help, but if you think that this is not a good way of solving the problem then please be my guest to come up with or teach me of a better way to do the same thing.

{The code:

import pygame
import sys
from pygame.locals import *white = (255,255,255)
black = (0,0,0)
objs = []
MAIN_BUTTON = 1class Pane():def __init__(self, textToDisplay, coordinates, screen):self.textToDisplay = textToDisplayself.coordinates = coordinatesself.screen = screendef drawPane(self):self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))pygame.draw.rect(self.screen, (black), self.coordinates, 2)pygame.display.update()class Screen():#constants/array(?) outlining the x,y boundaries of each of x10 panes#Note to self - Remember to change co-ordinate valuesNoOfPanes = 0Panes = []def __init__(self):pygame.init()pygame.display.set_caption('Box Test')self.font = pygame.font.SysFont('Arial', 25)Screen = pygame.display.set_mode((1000,600), 0, 32)self.screen = Screenself.screen.fill((white))pygame.display.update()def addPane(self, textToDisplay):paneLocs = [(175, 75, 200, 100), (0, 0, 200, 100), (600, 400, 200, 100), (175, 75, 200, 100), (175, 75, 200, 100), (175, 75, 200, 100), (175, 75, 200, 100), (175, 75, 200, 100), (175, 75, 200, 100), (175, 75, 200, 100)]if self.NoOfPanes > 10:print("Limit Reached")            else:            myPane = Pane(textToDisplay, paneLocs[self.NoOfPanes], Screen)myPane.drawPane()self.NoOfPanes = self.NoOfPanes + 1pygame.display.update()def mousePosition(self):global clickPosglobal releasePosfor event in pygame.event.get():if event.type == MAIN_BUTTON:self.Pos = pygame.mouse.get_pos()return MAIN_BUTTONelse:return Falseif __name__ == '__main__':myScreen = Screen()myScreen.addPane("1")myScreen.addPane("2")myScreen.addPane("3")myScreen.addPane("4")while True:ev = pygame.event.get()for event in ev:if event.type == pygame.MOUSEBUTTONUP:posx,posy = pygame.mouse.get_pos()if (posx >= 175 and posx <= 375) and (posy >= 75 and posy <= 175):print("BOB") #Bob was there just for test purposesfor event in pygame.event.get():        if event.type == pygame.QUIT:pygame.quit(); sys.exit();
Answer

Fix your case.

class Pane():def __init__(self, textToDisplay, coordinates, screen):...self.screen = screendef drawPane(self):self.Screen.... # <<< HERE
https://en.xdnf.cn/q/119170.html

Related Q&A

Two variables in Django URL

I want a URL something like this:/(category)/(post-slug)On the link this is what I have:{% url blog.category blog.slug %}and for the url.py:url(r^(I DON"T KNOW WHAT TO PUT ON THIS PART TO GET THE …

Python 3.2 Replace all words in a text document that are a certain length?

I need to replace all words in a text document that are of length 4 with a different word. For example, if a text document contained the phrase "I like to eat very hot soup" the words "l…

Python split list at zeros [duplicate]

This question already has answers here:Closed 11 years ago.Possible Duplicate:Remove leading and trailing zeros from multidimensional list in Python if I have a list such as:my_list = [[1,2,0,1], [1,0…

Creating Dynamic Text Using the blit method [duplicate]

This question already has answers here:How to display text with font and color using pygame?(7 answers)Closed last year.Im creating a basic game where a black square moves around the screen. There are…

Regex to match special list items

I have weird list of items and lists like this with | as a delimiters and [[ ]] as a parenthesis. It looks like this:| item1 | item2 | item3 | Ulist1[[ | item4 | item5 | Ulist2[[ | item6 | item7 ]] | i…

How to choose the best model dynamically using python

Here is my code im building 6 models and i am getting accuracy in that, how do i choose that dynamically which accuracy is greater and i want to execute only that model which as highest accuracy."…

How do you access specific elements from the nested lists

I am trying to access elements from the nested lists. For example, file = [[“Name”,”Age”,”Medal”,”Location”],[“Jack”,”31”,”Gold”,”China”],[“Jim”,”29”,”Silver”,”US”]]This data c…

Why does BLOCKCHAIN.COM API only return recipient BASE58 addresses and omits BECH32s?

Following this post, I am trying to access all transactions within the #630873 block in the bitcoin blockchain.import requestsr = requests.get(https://blockchain.info/block-height/630873?format=json) …

rename columns according to list

I have 3 lists of data frames and I want to add a suffix to each column according to whether it belongs to a certain list of data frames. its all in order, so the first item in the suffix list should b…

How to send a pdf file from Flask to ReactJS

How can I send a file from Flask to ReactJS? I have already code that in the frontend, the user upload a file and then that file goes to the Flask server, then in the flask server the file is modify, …