I can't draw solid rectangle


shark coding

I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code:

my_color = (0, 0, 0)

my_rect = (100, 100, 200, 150)

box = pygame.Surface.fill(my_color, my_rect)

surf.blit(box)
Kingsley

You just need to do it in two steps. Create the surface first, then fill it. Creating the surface generates a separate image, so it needs a dimension instead of a rectangle.

my_color = (0, 0, 0)

my_rect = (100, 100, 200, 150)

my_size = ( 200, 150 )

box = pygame.Surface( my_size )
box.fill( my_colour )

surf.blit( box, my_rect )

If you just want to draw a rectangle, you can use drawing functions , which use the underlying surface directly:

pygame.draw.rect( surf, my_color, my_rect )

Related


I can't draw solid rectangle

shark coding I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code: my_color

I can't draw solid rectangle

shark coding I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code: my_color

I can't draw solid rectangle

shark coding I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code: my_color

I can't draw solid rectangle

shark coding I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code: my_color

I can't draw solid rectangle

shark coding I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code: my_color

I can't draw solid rectangle

shark coding I am trying to draw a screen with a filled box in the middle. I am using pygame.Surface.fill()this box, but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' object is not applicable to 'tuple' object Here is my code: my_color

Can't draw rectangle on JPanel

Jonah I'm currently trying to learn more about swing painting and am creating a little game but seem to be stuck. I'm trying to add several rectangles (enemies) to an ArrayList and then draw them in a paintComponent()method , but that doesn't seem to work. Thi

Can't draw rectangle on JPanel

Jonah I'm currently trying to learn more about swing painting and am creating a little game but seem to be stuck. I'm trying to add several rectangles (enemies) to an ArrayList and then draw them in a paintComponent()method , but that doesn't seem to work. Thi

I can't draw rectangle using canvas as child component

Riddle I need to draw a rectangle using canvas. Canvas must be in child component. Just like the updateCanvas function. Is it possible to do so? I am trying to draw a rectangle in the parent component and everything works fine, but in this case I need to put t

I can't draw rectangle using canvas as child component

Riddle I need to draw a rectangle using canvas. Canvas must be in child component. Just like the updateCanvas function. Is it possible to do so? I am trying to draw a rectangle in the parent component and everything works fine, but in this case I need to put t

How to draw solid rectangle in JFreeChart?

newyhulk14: I am writing a small application using Swing and JFreeChart. I have to display one XYLineChartand I want to draw some filled rectangle on it. I used XYShapeAnnotationdraw rectangle and tried to fill rectangle Graphics2Dwith but it doesn't work. I h

How to draw solid rectangle in JFreeChart?

newyhulk14: I am writing a small application using Swing and JFreeChart. I have to display one XYLineChartand I want to draw some filled rectangle on it. I used XYShapeAnnotationdraw rectangle and tried to fill rectangle Graphics2Dwith but it doesn't work. I h

How to draw solid rectangle in JFreeChart?

newyhulk14: I am writing a small application using Swing and JFreeChart. I have to display one XYLineChartand I want to draw some filled rectangle on it. I used XYShapeAnnotationdraw rectangle and tried to fill rectangle Graphics2Dwith but it doesn't work. I h

How to draw solid rectangle in JFreeChart?

newyhulk14: I am writing a small application using Swing and JFreeChart. I have to display one XYLineChartand I want to draw some filled rectangle on it. I used XYShapeAnnotationdraw rectangle and tried to fill rectangle Graphics2Dwith but it doesn't work. I h

How to draw solid rectangle in JFreeChart?

newyhulk14: I am writing a small application using Swing and JFreeChart. I have to display one XYLineChartand I want to draw some filled rectangle on it. I used XYShapeAnnotationdraw rectangle and tried to fill rectangle Graphics2Dwith but it doesn't work. I h

Can't draw rectangle on image in custom UIView

rational I have a storyboard scene with UIVIewcontroller. In this scene I have a UIImageview which contains a background image, a UIButton and a UIView. This UIView has an overridden drawRect method which has: - (void)drawRect:(CGRect)rect { [super drawRec

Can't draw rectangle on image in custom UIView

rational I have a storyboard scene with UIVIewcontroller. In this scene I have a UIImageview which contains a background image, a UIButton and a UIView. This UIView has an overridden drawRect method which has: - (void)drawRect:(CGRect)rect { [super drawRec

How can I draw this rounded rectangle?

Rishal Siddiqui enter image description here I'm a beginner in Android, doing an internship, and my task is to complete the app's navigation drawer. Any help would be greatly appreciated Hardik Taravia Create a new drawable and add the following code: <?xml ve

iTextSharp - Can't draw rectangle on table cell background color

hear I'm using iTextSharp to create a PDF from an HTML page as an example. I am trying to put a border around text to highlight certain items. Using the methods in these posts ( drawing a Rect at the curr position and adding text over the image ), I use the On

Can't Graphics.drawRect fully draw a rectangle?

mor I'm trying to create my own swing component, but when I try to draw the border using drawRect, it only draws the left and top edges! Why is this happening and how to fix it? Here is my paintComponent method: @Override protected void paintComponent(Graphics

Can't Graphics.drawRect fully draw a rectangle?

mor I'm trying to create my own swing component, but when I try to draw the border using drawRect, it only draws the left and top edges! Why is this happening and how to fix it? Here is my paintComponent method: @Override protected void paintComponent(Graphics

iTextSharp - Can't draw rectangle on table cell background color

hear I'm using iTextSharp to create a PDF from an HTML page as an example. I am trying to put a border around text to highlight certain items. Using the methods in these posts ( drawing a Rect at the curr position and adding text over the image ), I use the On

How can I draw the image into a rounded rectangle? (JAVA)

F_Schmidt: How to draw buffered image to a rounded rectangle? I overridden a method of paintComponent, but the call graphics.setClip(new RoundRectangle2D.Double(0, 0, getWidth()-1,getHeight()-1, getArcRadius(),getArcRadius()));is not not working because a roun

How can I draw a blue rectangle when the mouse is pressed?

Abby: Here is my code. I want to draw a blue rectangle when the mouse is pressed. The rectangle will be centered around the mouse pointer. I'm new to events so any help would be greatly appreciated. import javax.swing.*; import java.awt.*; import java.awt.ev