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?
Related
My hello message is not visible...
I'm writing a 3D video game using Python (3.10) language with Panda3d (1.10) as 3D game engine.
Some graphical parts of the game are not 3D, there are just 2D elements:
spell bar,
player resume
quest panel
skill tree
etc
spells/attacks book
and others
I see on the web that pictures are used to styling Panda3D Direct* components.
However, in my opinion, I think use statics pictures (.png for exemple) is not efficient when game design must be evolved. That's why I prefer use HTML/CSS to render 2D elements, especially since CSS is very powerful if you know how to use it. I prefere to use SVG into the scene but I don't understand how create SVG file.
So, my question is:
Can I use HTML/CSS inside a Panda3d application?
Thank to all!
Have a nice day!
I think I've found a workaround (temporary).
I create HTML/CSS file that styling my 2D component that must be injected inside the Panda3D scene
I create a Python script that convert an HTML part as PNG picture using RGBA for transparency
I use the generated PNG picture inside my Panda3D scene on the target component.
It's not pure HTML/CSS, but it can works.
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.
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
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.
I am looking to make a GUI in python but currently do not have much experience. The GUI must have a few key features, namely a slider bar to control audio, and a few basic menu buttons. I realize essentially all GUI development tools could handle these simple features, but I am also interested in some custom content as well. The basic look of the GUI I am looking to create is shown here:
In the image, the slider volume bar, "button1," "button2," the colored circles, and any slice of the circle (one highlighted section is shown) needs to be clickable and interactive. Moreover, the small colored circles must be able to dynamically revolve around the edge of the circle and remain clickable at all times. I have not used any GUI development tools yet, but have looked into pyGTK, pyQT, wxWidgets, and Kivy. Can anyone who has used these tools recommend which would be best suited? As far as shapes of buttons, am I restricted?
You can use pyopengl, pygame , pygtk .
I have one example how to show this images if you want take a look at :
http://free-tutorials.org software free section is decor.tgz example.
In my opinion you can use pyOpenGL is very portable to another language like C,C++ and also you can make it to Linux , Windows , Android.