How do I open a gif in Python? - python

I'm wondering if it's possible to play an animated gif using Python. I'd just like to display a set of them and iterate at a certain interval. I'm wondering what the best route to take to open them in python. Is it possible to open with Preview (I'm using a Mac) or perhaps a web browser package?

You can do this using Tkinter library in python. You can even add buttons, labels etc..
More Information:
https://docs.python.org/2/library/tkinter.html#a-simple-hello-world-program
http://effbot.org/tkinterbook/photoimage.htm

Related

How can I use Python (2.7) to read Windows notifications?

Is there a way to read in Windows system notifications (the bubble dialogs in the lower right hand corner of the screen) using Python? I am trying to read in the text of the notification as well as the time at which it was generated, but I've been unsuccessful in locating any information on how to do this.
I have found several resources over how to generate these notifications, such as this question: How to create a system tray popup message with python? (Windows), but nothing on how to read these popups if they are generated outside of Python.
Thanks in advance for your help!

Is it possible to save in a file an animation created with Tkinter?

I wanted to use Python to create animations (video) containing text and simple moving geometric objects (lines, rectangles, circles and so on).
In the book titled "Python 2.6 Graphics Cookbook" I found examples using Tkinter library. First, it looked like what I need. I was able to create simple animation but then I realized that in the end I want to have a file containing my animation (in gif or mp4 format). However, what I have, is an application with GUI running on my computer and showing me my animation.
Is there a simple way to save the animation that I see in my GUI in a file?
There is no simple way.
The question Programmatically generate video or animated GIF in Python? has answers related strictly to creating these files with python (ie: it doesn't mention tkinter).
The question How can I convert canvas content to an image? has answers related to saving the canvas as an image
You might be able to take the best answers from those two questions and combine them into a single program.
I've accomplished this before, but not in a particularly pretty way.
Tl;dr save your canvas as an image at each step of the iteration, use external tools to convert from image to gif
This won't require any external dependencies or new packages except having imagemagick already installed on your machine
Save the image
I assume that you're using a Tkinter canvas object. If you're posting actual images to the tk widgets, it will probably be much easier to save them; the tk canvas doesn't have a built-in save function except as postcript. Postscript might actually be fine for making the animation, but otherwise you can
Concurrently draw in PIL and save the PIL image https://www.daniweb.com/software-development/python/code/216929/saving-a-tkinter-canvas-drawing-python
Take a screenshot at every step, maybe using imagegrab http://effbot.org/imagingbook/imagegrab.htm
Converting the images to to an animation
Once the images are saved, I used imagemagick to dump them into either a gif, or into a mpg. You can run the command right from python using How to run imagemagick in the background from python or something similar. It also means that the process is implictely run on a separate thread, so it won't halt your program while it happens. You can query the file to find out when the process is done.
The command
convert ../location/*.ps -quality 100 ../location/animation.gif
should do the trick.
Quirks:
There are some small details, and the process isn't perfect. Imagemagick reads files in order, so you'll need to save the files so that alphabetical and chronological line up. Beware that the name
name9.ps
Is alphabetically greater than
name10.ps
From imagemagick's point of view.
If you don't have imagemagick, you can download it easily (its a super useful command-line tool to have) on linux and mac, and cygwin comes with it on windows. If you're worried about portability... well... PIL isn't standard either
There is a way of doing that, with the "recording screen method", this was explained in other question: "how can you record your screen in a gif?".
Click the link -->LICEcap : https://github.com/lepht/licecap
They say that it's free software for Mac (OS X) and Windows
You could look at Panda3D, but it could be a little over killed for what you need.
I would say you can use Blender3d too but i'm not really sure of how it works. Someone more experimented then me could tell you more about this.

Basic Drawing in Python

As a class project, I need to create a graphics library in Python. What is the most basic way I can create windows and access individual pixels? Tkinter seems like an over kill since it already has built-in methods to draw lines. Is there a more basic way to do graphics in python?
If you want to just create bitmaps and save them as jpeg or pngs or bmps see Save as image?
If you want to get graphics contexts and draw to the screen see How can I draw a pixel to screen in python? or Best Python library for drawing?.
If you want to play with Graphical User Interfaces see Python any good for GUI dev?

How to add user-resizable images in a textbox for Python GUI

I'm trying to make a word processor type program in python. I'd like the user to be able to open a resizable image into the text area like in MS Word. I've looked into wxpython and tkinter. My understanding is that wxpython doesn't have a feature for images inside textboxes, and I'm not sure if tkinter has a way of letting the user resize the image. Is there a way for me to add this feature using one of the popular GUI toolkits?
Use PyQt. You can achieve lot of things through the highly capable library offered by them.
Another option is to use PyGTK.
Both toolkit also offer GUI building tools for ease of creation.

How to display interactive SVG in a window on Linux?

I really like SVG, it's very nice to draw with it. So far i've made static images using Inkscape. I'd like to make them interactive though.
I did some trials, following tutorials like this one. But i can see a SVG and interact with it in my web browser only. I'd like to make such things in a window on the desktop.
There are drawing kits like Cairo or OpenGL, but then i have to draw from code. It seems a more clever thing to use SVG (which was drawn using Inkscape).
What does it require to view interactive/animated SVG in a plain desktop window/canvas? I've seen some modules to convert SVG to Cairo: but is there a direct SVG intepreter for Linux?
The problem is that the effects require javascript and cascading style-sheets, which basically means complete web rendering engine. So the easiest way is to use one, either webkit or gecko (webkit has probably better support for SVG these days, plus I can't find package of gecko right now).

Categories