I have a Label that will eventually display an image, but when the program starts I just want it to be blank. However, I also need to set the width and height of the Label in order to make the layout look good.
Because Label treats width and height as number of lines/characters when the image attribute isn't set, things look very wrong.
So how can I make the Label behave as an image (pixel width/height) without actually setting an image?
Related
I want to put text on images with specified width and height, just like stretching its width and height using PIL in python.
Sample image for the text i want
Currently, I am creating a transparent canvas, resizing it to the width and height specified with the text on it using,
canvas = canvas.resize((width, height), Image.LANCZOS)
after its dont, i paste it on the image i want. This process is quite slow, i directly want to put the text without creating another canvas and pasting it on the image.
I would be glad if someone would be able to help,
Thank you!
I am trying to append an image to a frame I have. However, I have many frames within each other so I don't know what the dimensions of this frame are.
Is there any function or anything that will output the dimensions of the frame like "100x500", for example?
Thanks
Every widget has the methods winfo_width and winfo_height which return the current dimensions of the widget. You can also use winfo_reqwidth and winfo_reqheight to get the requested width and height. The two can be different if the size of the widget changes due to how it is managed (eg: when using sticky with grid, or fill with pack.
If the window has not yet actually been rendered, the width and height returned by winfo_width and winfo_height will be 1.
I am using tkinter and the PIL to make a basic photo viewer (mostly for learning purposes). I have the bg color of all of my widgets set to the default which is "systemfacebutton", whatever that means.
I am using the PIL.Image module to view and rotate my images. When an image is rotated you have to choose a fillcolor for the area behind the image. I want this fill color to be the same as the default system color but I have no idea how to get a the rgb value or a supported color name for this. It has to be calculated by python at run time so that it is consistent on anyone's OS.
Does anyone know how I can do this?
You can use w.winfo_rgb("systembuttonface") to turn any color name to a tuple of R, G, B. (w is any Tkinter widget, the root window perhaps. Note that you had the color name scrambled.) The values returned are 16-bit for some unknown reason, you'll likely need to shift them right by 8 bits to get the 0-255 values commonly used for specifying colors.
I am making a program where pictures are displayed to the user. Some of these pictures are, however, too long and run off the canvas. The canvas is a set size(width=600, height=150). I am wondering if there is anything to make sure the longer pictures do not exceed this width and are shrunk down when they do so they fit.
The images are in .gif format.
I have tried using subsample() and zoom() but these seem to shrink the images even when they already fit on the canvas making them too small.
subsample and zoom are the only way to resize images with the tkinter PhotoImage objects. Whey you call them, they will always shrink or grow the image. It is up to you to determine which one to call, and what arguments that will give you the closest approximation to the desired size.
Someone know if it's possible to change the color of a pixel in a canvas without using un object, so without using something like canvas.create_oval or canvas.create_rectangle ?
There is no way to color a pixel other than to create a 1x1 pixel object of some sort. And yes, at some point you will experience performance problems. The canvas simply wasn't designed to be used this way.
If you're really needing to create a large area in which you can manage individual pixels, you can create a canvas with a single image that is the same size as the canvas. You can then set the color of individual pixels on the image through the photo image interface.
Within tkinter itself, it's impossible.
Even if you manage to change a pixel on canvas window (which is possible with X11 and Windows APIs in a platform-dependent way), you'd have to ensure it's repainted properly.
You can, of course, place a frame of size 1x1 over the canvas, with a background color you want. This way, pixel is "changed" and no canvas object is created. If there's a real (though strange) problem behind a question, this trick could be a solution.