Tkinter contents of both widgets visible when overlapping - python-3.x

So, I am trying to make a video game in Tkinter (no, I don't want to use PyGame), but I have ran into a bit of a problem.
I have realized that sometimes you may want to have two widgets overlap (e.g. sprite on top of background) but have the contents of both widgets to be visible. For example, I might have a sprite with transparent sections.
How do I set the "background" option of a widget so that there is no visible background?
Note: "you can't do this" answers are acceptable.

This is not really posible in Tkinter. But you can set the transparency of the whole window with root.attributes('-alpha', 0.5)
For windows, you can do root.attributes("-transparentcolor", "red"), but again it will be applied to the whole window, not just the single widget.

Related

Non rectangular shape or transparent background tkinter or any other library python?

Here is my problem. I developed a tkinter GUI for my project. However I am stuck with tkinter limitations. I developed python gui to create a virtual view for a red table as below. The window does not have any border or title. It is just put on the a picture background which is outside of the code.
However as you can see it is not lively enough for me. I want it to look like this:
Is there a way to do this in tkinter? I tried transparent backgrounds, however in Ubuntu transparent background with visible object is not possible. Also You cannot make different window shapes other than rectangle. What is your suggestions? Should I use another library. I really need an expert opinion about this.
Transparent background reference
Different window shape other than rectangle
My environment : Ubuntu 16.04 Python 3.5.2
You can't specifically change the shape of a Tkinter Window, but you can create a canvas and design your own shape (then add your buttons and labels on this canvas if needed).
You can also take a look at PyQt or Kivy, but if you are confortable with Tkinter go with Canvas.
So to solve my issue I found a python library wxPython:
You can check this link it creates Wx non rectangular shape
It creates the the window using inheritence. I tried selected answer and It solved my question.
Btw I tried QTPython, Kivy, tkinter. Non of them had straight example such wxPython.

Layout management inside Cairo DrawingArea/Context?

I have a window in mono gtk#, which has lot of VBoxes & HBoxes. These boxes contain some buttons, labels, and some other widgets also. Now I need to make this window alone to transparent.
I created one drawingArea by referring zetcode page.
But inside this drawing area I'm not able to do the arrangements of my widgets, one Move function is available, but it is not much use for me. So how do I do widget arrangement neatly inside a drawingArea?

How to make graphic with python, Tkinter or not, not inside the rectangular window?

For example like those gadget where is a figure walking around the screen, or any graphics not bounded inside rectangular window, and even is interactive ?
The trick is to do a transparent window and hide the title bar
both are feasible with most graphic library but will be rarely cross platform
I will advise you to look at this question to hide the title bar with tkinter
Tkinter doesn't support transparency so you may need to use wxPython instead

How to track the bottom of a frame when used on a canvas with a scrollbar?

I implemented the code from this solution:
Adding a scrollbar to a group of widgets in Tkinter
I use it basically as a console displaying messages etc.
I need the same effect as for the text widget using
self.textwidget.see(END)
Meaning the frame would follow the widget on the bottom.
I tried using focus() on the bottom widget, but that didn't work and made it look really wierd.
SIDE NOTE:
In Bryan Oakley's solution when scrolling the widgets they bleed over the canvas. To fix it place the canvas into another frame which has the same size.
In his solution it can't be seen too well, but using let's say sunken relief it is truly disturbing. Also then use the relief on the outer frame not the canvas.
Call the yview_moveto method of the canvas. It takes an argument which represents what percentage of the widget should be at the top of the window. The value 1.0 guarantees that the bottom of the scrollable canvas will be in view.
the_canvas.yview_moveto(1.0)
Note that this only works after the event loop has had a chance to render the items on the screen (ie: you can't call this immediately after adding things to the frame, unless you explicitly call update)

Desktop effects (compiz) turned on: How to capture the image of a window WITH border/frame/title bar?

I would like to get the image of an X server Window (toplevel window, parent is the root Window) with its border/frame/title bar. I have already tried several libraries (Xlib, XRender, gdk, cairo) but none of them works. The captured image has the same geometry as the window but the frame is missing.
The problem is that the child window which should hold the frame image is InputOnly. The reason might be for this that the frame is rendered by the window decorator on the fly the same time as the Window itself.
I cannot capture the image from the RootWindow as the Window might be partially or entirely covered.
Redecorating the captured Window image could be an alternative.
Any suggestions? Thanks.
PS. When compiz is not running everything works as expected.
I use shutter for screen shots on linux, it's super easy to capture whatever portion of the screen you want. As a bonus, there are tools to add arrows or highlight sections.
http://shutter-project.org/preview/screenshots/

Resources