Drawing onto a text widget in tkinter - python

I was wondering whether it is possible to use some of the tkinter canvas drawing methods on a text widget. Ideally I would have the text widget placed onto the canvas so that I can draw onto the canvas and make it look like it shows up on the text widget.

No, it is not possible to draw over or into a tkinter Text widget. You can, however, add text to a canvas with the create_text method and draw over that.

Related

tkinter: Scrollbar bar widget with resizable handle

Is there a widget usable in Python with tkinter, which is a scrollbar with resizable slider? This makes sense e.g. when displaying something in graphical format to pan (moving the slider) and zoom (resizing the slider) with the same widget.
In a waveform viewer from Cadence it looks like this:
You can resize the handle using the little triangles or just grabbing the left or right edge of the handle with the mouse.
No, there is nothing like that in tkinter. Tkinter provides the basic building blocks, however. You could probably craft one using frames or a canvas.

Tkinter ~ Is Drawing a Canvas to GUI possible using .grid()?

Is it possible to draw lines such as the following with the Tkinter .grid() system? Every tutorial that talks about canvas drawing uses .pack() exclusively.
There are no answers for using canvas with .grid() when you search online.
I have tried using canvas with .grid() but my GUI got completely messed up and no lines were drawn.
Is it actually possible to use canvas with .grid()?
You use neither grid nor pack for drawing items on a canvas. The canvas has the following methods for drawing:
create_arc
create_bitmap
create_image
create_line
create_oval
create_polygon
create_rectangle
create_text
create_window
If you're not actually asking about drawing figures on canvas, but on adding the canvas to a window with pack or grid, you can use either.

Text widget over image in Tkinter

Is it possible to have a text widget over an image? In other words, I need to have a background image and be able to write text on that image (overlaid).
It is not possible to overlay an image with a text widget, and have the image be visible under the widget.
What you can do instead is use a Canvas widget, display the image in the canvas, and then create text items on the canvas. Text items on the canvas are editable, though you have to do a little work to set up some bindings.
There is a good explanation of how to create editable text items on a canvas here: http://effbot.org/zone/editing-canvas-text-items.htm

How to create a Label widget with a transparent background using tkinter?

I wanted to create an app which has an image as its background. But when I add a Label over the image, the label had a white background.
Is there a way to set the Label widget's background color to 'transparent'?
I'm not aware of a way to make Label backgrounds transparent. One alternative is to use a Canvas widget as the base for the whole thing, then use the create_image method to add the background image, and create_text to make the text labels. It will be a bit more work, but the text should render without a background on top of the image. (Admittedly I have very little experience with the Canvas widget, so I'm speaking more from theory than experience, but it's worth a try.)
If you don't have a good Tkinter reference, I highly recommend this one made by New Mexico Tech. It's available as a downloadable PDF as well.

Can I draw on top of a canvas inside of another canvas?

I am creating a Solitaire clone using Python's Tkinter window toolkit. My window contains a main canvas, and within the main canvas a series of widgets that inherit from Canvas that hold the cards. I have implemented a "Drag to Move" system where a user can click the mouse down to select a card in one of the inner canvases, drag it to a new canvas, and let go to place the card into the receiving canvas.
The Problem: I want to draw the cards in motion between the canvas on which they are drawn, and the canvas they are moving to, so the user can see them moving across the screen during the click and drag motion. When I try to draw cards in-between the canvases that I already have, they are always drawn behind, meaning I can only see cards through the padding around the inner canvases.
Here is an example where I drew several of them so the effect could be seen clearly, and the inner canvases are also clearly visible.
What I've Tried: I've tried to move the canvases back using Misc.lower(aCanvas), but i wasn't able to create the desired effect. I've also tried to design a custom overridden cursor, but it seems my cursor size is limited to 32px*32px, which is insufficient for the size of the card images I want to move.
My Question: How can I draw on top of a canvas that is inside of another canvas? If I can't, how would you solve this problem?
You cannot do what you want. Embedded widgets are always above the canvas items.
Why is it that you are embedding canvases insidebcanvases? Why not just use a single canvas?

Categories

Resources