I would like to draw directly to the screen from Python 3. For example, I would like to create a rectangle around a few icons on my desktop.
EXAMPLE
Or draw a line on the screen etc.
What are the libraries I should look up in order to do this? I prefer the performance wise solutions.
Related
I would like to create a home screen(menu) for my project using pygame(?).
I have a piTFT 2.8" Capactive display from adafruit.
I have design the whole display menu. Take a look on this demo screen for example:
Now I would like to built this on my pi. is there any easy way to position each element as can be seen on the attached image?
The display is 320 x 240, and I think if I try position the elements blindly it will take a lot of time which in this case, I dont really have spare time to waste.
Have you got any other suggestions about the use of pygame? Would you suggest me something different?
This answer may be a bit general, but what I do to find each position is go to paint or some paint program and then I add markers where positions are, then I can select rectangles and find there positions. It would be hard to find the positions by itself just from that image. Do you have a mac, windows, linux?'
just paste your menu, into the paint program and draw rectangles around certain icons, after that just go to the top left of the rect and it will tell you the position, so you will get both the width, height, and position.
I'm preparing exercises for school classes involving Python's turtle library.
The students are already drawing terrific pictures, but I want them to be able to detect existing pictures and colours in order to modify the behaviour of their program.
For example I would like to provide them with code which draws a maze using turtle, and then they can write the code to navigate the turtle around the maze (don't worry, I'll start simpler).
Is there a way to detect the colour of the pixels already drawn by the turtle?
Thanks!
Turtle uses Tkinter canvas, which you can get using turtle.getcanvas(), and according to this you cannot read the colour of a pixel without using a workaround of converting the canvas to a picture (bitmap) and read the bitmap.
You could try to keep an open array to work as the bitmap of your canvas and update it yourself as you draw new elements on the canvas, although that seems impractical unless the maze is simple and 'squary'.
I would use an array keep all x and y that is used for the maze in an array like stated above. Then have a size of a box around the turtle defined for detecting purposes.
I have a GTK drawing area and I want to have an image display as the background for it, while other things can be drawn over it.
My first attempt at this involved me simply taking the image, putting it into a pixmap, and drawing it before I draw other objects. This resulted in the objects backgrounds completely covering my background image.
Now I am thinking I need to change the object's pixmap's gtk.gdk.GC so the background color it has is transparent. Here is where I am having problems. I do not know how to set a gtk.gdk.Color's alpha.
How do I set a gtk.gdk.Color's alpha? (or any other way of making the color transparent)
If this idea seems unlikely to work please let me know. I am pretty new to GTK.
I don't know if this can help you, but my best advice is to use Cairo: an open source 2D graphics library providing cross-platform support for advanced 2D drawing. It is also the easiest way to draw 2D graphics, I think
(I've tried GDK in the past and I thought it was much more tricky to use).
In python you can use the specific bindings Pycairo.
Here you can learn more about it, with easy tutorials.
For your specific problem, see more about images
and trasparency.
The main function for trasparency are:
set_source_rgba(red, green, blue[, alpha=1.0])
paint_with_alpha(alpha)
A great summary to learn how to manage images and transparency is in the example Reflected image in the same page linked before about trasparency.
I'm looking for a way to draw real translucent lines with pygtk or wxPython, I now this is not possible with TKinter (I like this one because its already there). Also, I already now I can do this using PIL, but I want to draw direct to a canvas and it will be a dinamic content so I think using PIL will be a slow solution (and not elegant). Someone know a way to do this? Or maybe another toolkit that allows me to do this.
To get clear what I want is: If I drew lines with distinct colors that overlaps I need to be able to see both lines with a merged color at the intersection. Something like if the color I choose for the pen have a transparence instead of solid color.
Thanks.
Pretty much all "canvas" libraries have brushes with alpha.
PyGTK has the gtk.DrawingArea, often used with cairo.
Cairo can be used with wxPython as well.
QT has the Graphics View Framework.
I'm trying to build an application in Python that can draw things on top of video. I have not found a way to do this using gstreamer + Tkinter; I don't think tk lets you do transparent Canvases. So I've looked at using gtk instead, but I'm a bit lost- I would like to be able to just drop some sort of transparent overlay on top and push pixels, but I don't think there's such a thing as a transparent DrawingArea, either. So I need a way to edit the contents of a DrawingArea after each frame of video is in it but before it's shown to the screen. I tried using expose-event but that hasn't worked.
Any suggestions on where to go from here? I want my final product to be a little interface to let the user draw lines and polygons on top of a video as well as drawing pixels programatically- and, if possible, save the result to frames and/or video. So a direction that is more likely to make that possible would be preferred.
Edit: Tried using the "handoff" signal but it flickers madly. PiTiVi has a custom Pipeline that has a state-changed signal which they use to draw lines and circles with Cairo. So this is totally doable...
Edit 2: Right, okay. PiTiVi only draws when the video is paused; I guess I can deal with that. That's what it was using the state changed signal for- you can watch for state change messages and emulate a signal. I can deal with that, but it would be really nice to draw over every frame.