How to show images in python3 - python-3.x

I'm a beginner and I'm having problems of showing images in python3. I would like to know what are some codes that could show images in python 3,f or a mac user. Thanx!

Do you have some more context? Where are you trying to display the image?
Your best bet is probably to open another program and give it the path to the image you want to display. To open the file ~/screenshot.png, for example, you could run
from subprocess import run
run(["open", "~/screenshot.png"])
This is pretty delicate however. It requires the user to have open installed on their computer, and for that executable to do what you expect it to do. Depending on what your usecase is, it might make more sense for you to use a graphical library to draw the image.

Related

Trying to install GMAT

I'm relatively new to the world of Linux on a Chromebook, so I probably won't know what you talking about unless you make it really clear.
For those who don't know, GMAT is a NASA software tool to model orbits, spacecraft, and celestial bodies. I am 99% there, but I get stuck on a screen that says to "enter a script file, q to quit, or an option". I would really like to create a launcher so I can open GMAT, but all the places I go just make it more confusing. Any thoughts?enter image description here

How to create & save a tkinter.Canvas image on a server w/ no display

I've written a program that generates an image via tkinter.Canvas and saves it. Now I'm updating this project to use FastAPI to let users hit my end-point and download this image.
I'm not trying to display the image on the server, just generate it in memory, save it to storage, then return that image.
Initial proof-of-concept tests work, but I cannot get this to work in Docker because no $DISPLAY is set. Unlike other questions I've seen, I'm not trying to display the image directly, just generate the image, save it, and return a file-path.
This is not a dupe of Tkinter setup on headless server. That question boils down to "how do I not run tkinter while on a server?" I still need tkinter, I just have no intention of displaying it.
I have also seen something about X11, but it seems like I'd need to know the server's environment in order to install X11, and I do not.
Is tkinter really not able to generate an image without $DISPLAY (even if I don't intend to display it)? If so, is there an alternative to tkinter I can use that can generate an image without needing a $DISPLAY? Am I totally misunderstanding a major part of how this works? It seems like I should be able to generate an image and save the bytes without needing all the things required for actual graphical rendering...
Using Pillow.Image and Pillow.ImageDraw instead of tkinter works for my scenario. (Credit goes to #acw1668)
My project only draws lines, circles, and polygons - all things that ImageDraw can do. The process of switching from one to the other was exceptionally straightforward, and Docker returns the ImageDraw/Image file with no issues!

Python curses getmaxyx() always returning same value on windows

I am having trouble with using the python curses module for windows. I have used the wheel found here to get a script I had written on my mac to run on my desktop. For now, the script just displays a border around the window using the screen.border() method and another line across the whole width of the display. I displayed the bar across the screen using this:
dimensions = screen.getmaxyx()
screen.addstr(dimensions[0]/2, 0, "-"*dimensions[1])
I ran this in a loop, resetting dimensions each time and using getch to check for a curses.KEY_RRESIZE and then running screen.erase() to allow me to resize the window and the script will still work. When I ran this on windows after installing the wheel for python 3.7 (win32 because the amd64 one gave an error) I found that screen.getmaxyx() always returned the same value: the initial screen size, and never changed when I resized the window. I appreciate any help if anyone knows a way to fix this issue, or if I simply cannot use curses on windows, an alternative library for windows. Thank you!
Call resize_term(0, 0) after you get a KEY_RESIZE. (I’m not sure of the exact Python mapping.)
That ("on windows") is probably using PDCurses, which doesn't have a way to automatically update the screensize (e.g., as done with POSIX-based ncurses's SIGWINCH handler). Rather, it detects the window-size change and the application can call is_termresized to decide whether to tell the library to change the data structures to match using resize_term.
The python wrapper doesn't use that.

Create PDF reports on Linux

I'm facing the following situation at moment:
I need to generate a PDF report containing some parameters and graphs. I'm running a C daemon (on Arch Linux, Raspberry PI) which receives the data and should then generate such a report. My first version was using the library libharu and simply painted everything into the PDF.
This actually worked great but it's not a damn good solution, since I have to recompile the whole daemon if I want to change the style of the generated report.
I was thinking about using some kind of template, which I can load by my code and then render into the PDF. Does anyone know a library or something I could use for that?
I'm also open for other good ideas to solve my problem :-)

How to Crop Geotiff without GDAL using GUI based tool?

I need to crop Geotiff files without using command line GDAL. I am looking for a GUI based Geotiff or related file editor. I need to freely select any area to crop. I need to preserve lat long information so I can merge multiple Geotiff files. I would not mind converting Geotiff files to some other format and then crop and convert to Geotiff.
You need a desktop GIS. Qgis: http://www.qgis.org/ will do it along with a zillion other mappy things, or there's gvSIG, OpenJUMP, uDIG and others, see www.osgeo.org or search. Did I mention these are all free and open source?
Another idea is to use R, the statistics package. It can read in Geotiffs, plot them, allow selection from the graphics window, subsetting, and saving, but it is a programming language so a bit of typing is necessary. The process would be something like this:
r = raster("myraster.tiff")
plot(r)
bounds = locator(2) # you then click corners for cropping
c = crop(r,bounds) # might be 'extract' or 'mask' or something...
plot(c)
writeRaster(c,"clipped.tiff")
Excuse the vagueness.
For those who may be interested, we have started to work on an open source GUI utility, Rasterix, using GDAL and the Qt framework.
It can perform some of the tasks already implemented in several GDAL command line utilities for raster processing, but using a friendly graphical user interface.
The complete source code and the pre-built binaries for Windows, Linux and macOS are hosted on github at https://github.com/mogasw/rasterix.
We will add more features in the future, but should you be interested in something in particular, please let us know using github's issues.

Resources