I have seen many tkinter tutorials on images and almost all of them say that you have to use pillow to read png images, but tkinter.PhotoImage also does the job. Has there been a recent update to tkinter.PhotoUpdate or is there another reason for using pillow?
Has there been a recent update to tkinter.PhotoUpdate or is there another reason for using pillow?
Yes, there has been a fairly recent update to tkinter. PNG support is fairly recent, and still not available in every version of tkinter. You need a version of tkinter that is built on top of tk 8.6 or later.
You can check your version of tk by looking at the TkVersion attribute of the tkinter module:
import tkinter as tk
print(f"tk version: {tk.TkVersion}")
Related
We have a Python-based application written with WxPython 4 that we build for multiple operating systems, including Windows. In Windows 10, at least in my environment (inside a VM on a high resolution monitor), the text elements in the interface are blurry:
I can improve the situation somewhat by setting the Windows DPI-scaling override on the application. This is indirect and suboptimal, and it seems like there should be a way to do it from WxPython more directly. However, I have not found a way to do it.
Is there any way to set DPI scaling from WxPython, or otherwise fix blurry text on Windows in WxPython 4 directly from within the application?
According to a message from Python Issue Tracker and what I tried in the wxPython official Hello World, Part 2 example (helloworld2.py), adding following code to your program should work:
import ctypes
try:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except:
pass
I have a program which integrates a tkinter GUI as well as a matplotlib plot (using pyplot). I'm running into endless troubles having this program work correctly across a variety of Mac platforms. The main problem seems to be the appropriate selection of the backend.
In some cases, the program runs fine no problem. In other cases, I run into a similar issue documented in this question. Implementing the solution outlined there solves that problem, but then other errors pop up for other systems. The solution to these other errors appears to be to use the Qt4Agg backend.
There has to be some standard way of getting a program using tkinter and matplotlib at the same time to play nice with Macs. How can I programmatically make sure the correct backend is being used such that the program won't crash for a Mac user?
Sorry if this is vague but it is a very broad problem.
See this answer: How to switch backends in matplotlib / Python
In essence, if you do not know which backend is available, the following code should load up the first backend that is available on the current machine. (I have only included 4 backends, there are quite a few others).
import matplotlib
gui_env = ['TKAgg','GTKAgg','Qt4Agg','WXAgg']
for gui in gui_env:
try:
print("testing", gui)
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
break
except:
continue
print("Using:",matplotlib.get_backend())
Using: GTKAgg
Update: I am lead to believe that there is a backend for OSX called MacOSX which could be added to that list, although I have no way of testing it myself.
This is for primary school students who only have access to the main software, not Pygame or Tkinkter or any of that. This is a group of people named LPPJJAS sending this message and we woud like a code return.
Tkinter is documented as a standard Python library module. See the official documentation here. Tkinter is primarily a user interface widget toolkit rather than than an image processing library anyway, although one can display images in it.
But if for some reason Tkinter is not acceptable, the Pillow fork of the Python Imaging Library is probably the simplest option for an image processing library.
It's not a part of the base language but is maintained at the Python foundation's package index.
Executable installers for Pillow, for Windows and Python 2.7, as well as Python eggs and Python wheels (for Windows and other OS's), and setup instructions, can be found at the Pillow 2.9.0 official site. Choose the one appropriate to your version of Windows (32 or 64 bit) for Python 2.7.
There is also some documentation on the library itself at that site.
I am facing an image processing task, and I'm using Python 3.2 (on a 64-bit Windows system). All my searches for image processing libraries have come up with are libraries for older versions of Python (most notably PIL, whose current version - 1.1.7 - supports Python 2.7). Does anyone know of an image processing library for Python 3?
By the way, I do not need fancy transformations and heavy stuff. All I need is to open a JPG file and get the image as an RGB-value matrix/list.
Any help will be most appreciated!
You can get a source version of PIL which will compile on python3.1 here:
https://github.com/sloonz/pil-py3k
also binary installer for 3.2 and 64-bit windows here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil
ref: Image library for Python 3
The world is changing and everyone seem to be moving to a brand new library: Pillow. It is a drop-in replacement for PIL but it is alive and does support Python 3.
I'm looking for a terminal UI library providing widgets like buttons, checkboxes and so on, that is compatible with python3.
I've tried:
pycdk (pyrex does not work with python3, and porting it is a mess)
urwid (does not work with python3, it has a port but not working well with new curses interface).
Does anyone know such a library?
Thanks!
Cython supports Python 3, and I was able to make Cython accept the pyx file by changing all __new__ to __cinit__.
Note that the examples still needs some porting to Python 3 at that point. I get "TypeError: expected bytes, str found" when trying to run the examples. Switching all the strings to bytes worked.
Possibly it would be better if the API accepted strings under Python 3 too, but that is definitely more work.