tkinter scale with two sliders? - python

Does anyone know if it is possible to have a single scale widget with two "sliders" from the tkinter module? Or anyway to fake it?
Such as (edited with GIMP):
I am thinking placing one scale on top of another scale, but with a transparent background?

No, you cannot do this with the scale widget. You can't give it a transparent background and stack them.
If I had to implement this functionality, I would use a canvas widget and draw my own sliders.
It's not very hard to do, but obviously it's going to be more work than an off-the-shelf widget.

Here is a custom widget using a canvas, made by MenxLi.

I think this might work: Range Slider Module
You can see how it looks,

Related

How to trick Tkinter to make canvas invisible, but not its drawings? Python

(0) Introduction
Hello Everyone! I am an absolute beginner to Tkinter and not sure how to achieve my result. I tried several strategies and was disappointed multiple times. Didn't work due to my ignorance.
I am building my own little programming text editor.
I want to add functionality like yellow light bulbs in IntelliJ IDEA.
According to the idea, a yellow circle with a question mark appears on the screen next to a character which caused a syntax error in the code.
The question is not about positioning objects. I sort of confident in it. I am struggling with tk.Canvas imposing its background. I want to get rid of background and keep drawings visible.
(1) A "Naive" approach
In the code editor tk.Frame I have the following widgets:
tk.Text where user types code.
Positioned with .pack() method.
Line numbers tk.Canvas which is responsible for displaying line numbers.
Positioned with .pack() method
For each syntax error in the code I create a tk.Canvas object where I create yellow circle and question mark text.
Positioned with .place() method
It turned out, tk.Canvas _object has solid background which is covering half of the screen and looks ugly
(2) Attempted strategies, which failed
I looked for a way to make the Canvas object transparent, but from what I found, transparency is platform-dependent. Scary. I gave up.
I also tried to make the canvas have zero size with canvas.configure(width=0, height=0).
I was hoping that the canvas will become invisible and as a result, its objects will have a transparency illusion.
Unfortunately, Canvas objects, rectangles, circles and others are not displayed outside the canvas itself.
The image above is evidence of that property.
The circle is not displayed fully, because a part of it is outside the canvas rectangle.
(3) Some Ideas
I have a couple ideas, which haven't been attempted yet, due to the lack of confidence and research
3.1. Maybe Z-index hack ?
I hope, that It is possible to use a single tk.Canvas to store all circles.
The canvas will be placed in the same position as the text.
Tweaking z-indices, hopefully, can be done in such a way, that the canvas background will be "bellow" The text field, while the yellow circles will be "above" the text.
However. That Idea raises the following questions:
Does tkinter have absolute Z-indexing?
Do the Canvas objects (circles) share the same Z-index?
If so then I guess, the strategy is doomed and will fail. The Canvas is a widget, while as long as I know, canvas objects are not widgets.
3.2. Switch from Canvas approach to Images?
I heard that tk.Label can store Images.
I could draw a simple PNG of yellow circle with question mark. Maybe instead of canvas circle I could display these labels with images and use .place() to adjust their positions. Maybe worth trying.
(4) Summary of the question
How to hack tk.Canvas or achieve transparent background by keeking floating circles not transparent on top of a text? Thank you very much!
EDIT:
The target Platform is Linux.
Hence using root.wm_attrinutes("-transparentcolor", somecolor) hack doesn't work.

Best way of creating layout in pyqt5 to be resposive?

So I am curren]tly working on an app for image processing. I am using PyQt5 for this purpose. You can see how it looks like now on the picture below. My question is, what is the best way to make it responsive, meaning, if I resize the window, all the widgets will rescale as well. Right now I am using some groupboxes, Hlayouts, VLayouts.
Only thing that comes to my mind is to create a gridlayout, though I would like to know, if there is by any chance any other possibility how to easily do it, since there is quite a lot of widgets.
Also, I would like to ask about GroubBox widget. Down left I have four buttons which are in one groupbox whose border is set to none by self.tableButtonsGroupBox.setStyleSheet("tableButtonsGroupBox {border: none}"), but there is still visible the upper line. Is there way to get rid of it?
Thank you for suggestions in advance!

Python & translucent canvas

I'm looking for a way to draw real translucent lines with pygtk or wxPython, I now this is not possible with TKinter (I like this one because its already there). Also, I already now I can do this using PIL, but I want to draw direct to a canvas and it will be a dinamic content so I think using PIL will be a slow solution (and not elegant). Someone know a way to do this? Or maybe another toolkit that allows me to do this.
To get clear what I want is: If I drew lines with distinct colors that overlaps I need to be able to see both lines with a merged color at the intersection. Something like if the color I choose for the pen have a transparence instead of solid color.
Thanks.
Pretty much all "canvas" libraries have brushes with alpha.
PyGTK has the gtk.DrawingArea, often used with cairo.
Cairo can be used with wxPython as well.
QT has the Graphics View Framework.

Is it possible to make text translucent in wxPython?

I am adding some wx.StaticText objects on top of my main wx.Frame, which already has a background image applied. However, the StaticText always seems to draw with a solid (opaque) background color, hiding the image. I have tried creating a wx.Color object and changing the alpha value there, but that yields no results. Is there any way I can put text on the frame and have the background shine through? And furthermore, is it possible to make the text itself translucent? Thanks.
You probably need some graphics rendering widget. As far as I know, in wxPython you can use either built-in wxGraphicsContext or pyCairo directly. Cairo is more powerful. However, I don't know the details.
I would try aggdraw into a small canvas.
Any Static Text uses the platform's native label machinery, so you don't get that sort of control over it.

How do I overlap widgets with the Tkinter pack geometry manager?

I want to put a Canvas with an image in my window, and then I want to pack widgets on top of it, so the Canvas acts as a background.
Is it possible to have two states for the pack manager: one for one set of widgets and another for another set?
The answer to your specific question is no. You can't have two states or otherwise use pack two different ways in the same parent.
However, what I think you want to accomplish is simple. Use the built-in features of the canvas to create an image item that is part of the canvas, then pack things into the canvas as if it were a frame.
You can accomplish a similar thing by creating a label widget with an image, then pack your other widgets into the label.
One advantage to using a canvas is you can easily tile an image to fill the whole canvas with a repeating background image so as the window grows the image will continue to fill the window (of course you can just use a sufficiently large original image...)
I believe that Bryan's answer is probably the best general solution. However, you may also want to look at the place geometry manager. The place geometry manager lets you specify the exact size and position of the widget... which can get tedious quickly, but will get the job done.
... turned out to be unworkable because I wanted to add labels and more canvases to it, but I can't find any way to make their backgrounds transparent
If it is acceptable to load an additional extension, take a look at Tkzinc. From the web site,
Tkzinc (historically called Zinc) widget is very similar to the Tk Canvas in that they both support structured graphics. Like the Canvas, Tkzinc implements items used to display graphical entities. Those items can be manipulated and bindings can be associated with them to implement interaction behaviors. But unlike the Canvas, Tkzinc can structure the items in a hierarchy, has support for scaling and rotation, clipping can be set for sub-trees of the item hierarchy, supports muti-contour curves. It also provides advanced rendering with the help of OpenGL, such as color gradient, antialiasing, transparencies and a triangles item.
I'm currently using it on a tcl project and am quite pleased with the results. Extensions for tcl, perl, and python are available.
Not without swapping widget trees in and out, which I don't think can be done cleanly with Tk. Other toolkits can do this a little more elegantly.
COM/VB/MFC can do this with an ActiveX control - you can hide/show multiple ActiveX controls in the same region. Any of the containers will let you do this by changing the child around. If you're doing a windows-specific program you may be able to accomplish it this way.
QT will also let you do this in a similar manner.
GTK is slightly harder.

Categories

Resources