Is It Possible to Embed a Video In a Tkinter Window? [duplicate] - python

I posted a similar question a while ago but haven't received any answers so i thought i might ask a more generic question:
Does anyone know how to, through any means, output true video, not a rapidly changing sequence of images, in a Tkinter window with python?

You probably need an extension like TkVideo or Quicktime to do that, not sure there is a python style wrapper for it available yet.
https://github.com/patthoyts/tkvideo

Related

PySimpleGui - window size doesnt autofit dynamically

I'm trying to auto resize a PySimpleGUI window.
consider the following:
import PySimpleGUI as sg
CommandWindow = sg.Multiline(size=(80,20),echo_stdout_stderr=True,key=OUTPUT_KEY,visible=False)
window = sg.Window("FOO", layout=[CommandWindow],element_justification='center')
when the event is triggered, a sg.Multiline element's visible trait is updated to True.
then I refresh the window and it resizes (expands) to fit the element shown inside.
when I change the visible trait to False again, the window maintain its size and doesnt shrink back.
the execution as follows:
window[OUTPUT_KEY].update(visible=True/False)
window.refresh()
I think this will perhaps be the best answer I can come up with since StackOverflow answers do not age well, especially for the PySimpleGUI project which is ever-evolving.
The Demo Browser utility is made specifically to help answer questions like this. Of course, the documentation should also be used (PySimpleGUI.org).
The Demo Programs serve many purposes. One is to show specific techniques. The Demo Browser is a way for you to quickly and easily search, edit, and execute this code.
The attached screenshot is what I see when searching for "shrink" using this tool (as of Aug 2022...). The first item answers this specific issue. Maybe I got lucky? "I would rather be lucky than good". The docs and tools provided with PySimpleGUI are the best place to turn for questions rather than SO. They'll be the most accurate, the most up to date, and are part of the project itself.
Good lucky Jedi!
what solved it for me, Thanks to #Mike from PSG,
is using:
sg.Pin(,shrink=True)
as shown in docs: https://www.pysimplegui.org/en/latest/call%20reference/#layout-helper-funcs

How to make games that use graphic instead of text?

Hi I was wondering if anyone could answer my question, how would I go about making a game with graphics in python instead of text based games.
I'm only new though so if it involves another programming language then I'm probably can't do it yet.
Use tkinter module inside of python. To do this simply add from tkinter import * at the start of your program and open a window and use a mainloop to close it at the end. You can research how to use tkinter online on various different websites. I would suggest effbot as it's very useful for tkinter basics.
I would recommend using the tkinter library. You can makes games with graphics instead of text. One example would be here. And it is just Python :)

Is it possible to get tkinter messagebox icon image files?

I'm developing a python/tkinter application, and finding the default messagebox lacked flexibility, I programmed my own using Toplevel.
I was rather successful in recreating the messabox appearance, however, I could not find a way to obtain the icons displayed in normal tkinter messagebox (i.e. : error, warning, info icons...)
I did some research didn't find much, except that those image were stored in a win32 DLL file... Also tried looking into the tkinter messagebox module code, but its only an interface transferring from python to TCL code I can't find (and probably wouldn't be able to read anyway...)
Is there anyway to get files or rough equivalents (PhotoImage objects) for these icons using either python or TCL executed though Tk().tk.call()?
Or any other (thourghly explained then) way to achieve this?
Right now the best solution I can think of is to use screencapture, and save the icons to files, but I'd rather be able to access the original ones...
Thanks in advance !
The rough equivalents are available as (tk global variables):
::tk::icons::warning
::tk::icons::error
::tk::icons::information
::tk::icons::question
Like anything that is not documented, it is subject to change in the future, but these should be stable.

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.

Character Control using Python

I was wondering if anyone knows how to import a sprite and let it move when pressing the arrow keys in python, without using pygame, or some other library. This is purely out of curiosity, because I was just thinking about some sort of personal challenge, and that's what came to mind: a python game, without the help of pygame or libtcod. Is this possible, or do you need a library to do this for you? I'd appreciate anyone's input on this one.
Thanks.
What comes to my mind is using Tkinter's Canvas class. It is quite possible to do a simple program like that described using bindings on this class.
A good example of this may be found in Mark Lutz's Programming Python (http://shop.oreilly.com/product/9780596158118.do), the Moving Pics example.
If you don't own this, you can still look at the code for it as a reference by downloading the code using the link on the right side of the page. The path to the appropriat folder is /PP4E-Examples-1.3.1/Examples/PP4E/Gui/MovingPics/.

Categories