How to keep button ratio in a BoxLayout in Kivy - python

When using a BoxLayout in kivy and adding some button widgets using BoxLayout.add_widget() my buttons strech accordingly to the size of the boxes and the numebr of buttons. If my BoxLayout has an horizzontal orientation, the more buttons I add, the more they get shorter along the horizontal axis.
Since my buttons have an image, I would like the buttons to lengthen or shorten the more I add or remove widgets but keep a certain shape, perhaps square. So if the length is reduced, the width will do the same
If I'm not mistaken, using images instead they keep their shape without having to modify parameters (putting only the path to the image). The problem is that I don't know how to activate a certain function by clicking on the images.
Looking at the official documentation I can't find a solution to my problem. Thank you very much for your help.

Related

Create and align non-rectangular widgets together with PyQt6

I need to create a widget/layout, which will contain a number of non-rectangular, clickable widgets that are well aligned together so that they create a whole (picture below).
Each of theses widgets needs to be clickable and have a hover option. I thought of using QAbstractButton or QPushButton class and overriding it's paintEvent to draw it with a particular size and shape, but I don't know if this is a optimal solution. I also have no idea how I could then align these widgets together so that there are no empty spaces between them. I thought of using some absolute position of a parent Window and manually adjust child widgets position based on that.

Kivy - save full scrollview to image format

Does anyone know how make this (saving a scrollview stitched together as a series of images about the height of the screen) a reality?
There is the save_to_png method for every widget, but this only saves the currently visible portion of the screen. I'm not sure how to scroll down automatically by the height of the screen, and of course it would be better if there was a simple method for saving all of a widget to image, even if not currently rendered on the screen.
Any pointers on how to go about this?

Python Tkinter - How to move a textbox by pixels

What the title says.
I'm having a problem moving the textbox from a side to side.
The code's long and it's about 200+ lines so I wont post it here.
Anybody has an idea?
You have various options for this, depending on what you mean by "text box," and whether you want to move it "by pixels" or "from a side to [another] side."
If you just want to display text, you can use a Label widget. If you want a text box where the user can enter text, try an Entry widget. If you want to move your widget from one area of the screen to another, you can use the grid geometry manager and simply use grid_forget to "unplace" your widget then grid (with different options than you originally used, of course) to put it somewhere else.
If you just have text and you'd like to move it pixel by pixel, you could create a Canvas and then use that widget's create_text method to create some text in a specific place on the Canvas. You can the use the Canvas widget's itemconfig method to move the text to a new location.
If you need something more complex than text, like an Entry widget, and you want to move it pixel by pixel, do the same as above but use the create_window method instead.
See Canvas, grid, Label, Entry, and these SO questions about create_window.

Making a background canvas in kivy

I've read the questions about how to change a background, add a color, etc. in Kivy, and I'm familiar with how to do that for widgets.
My question is sort of a general strategy of what sort of object is intended to be used when all I want is a background that I'm going to put other widgets on---should that be a label or a widget, or a layout? (Suppose I'm only going to have a small padded background that I'll put a different colored gridlayout on, as in this question.)
I think the answer is really 'it depends'. As you say, you can add a background to anything, so the decision rests entirely on what kind of other behaviour you want the widget to have.
all I want is a background that I'm going to put other widgets on---should that be a label or a widget, or a layout?
If you want totally no extra behaviour, a Widget is fine. If you want simple behaviour like having the child automatically placed/size to fill the background widget, then of course a simple layout like BoxLayout will be ideal. Alternatively, you might want (for instance) the child to be made a little smaller than the background widget in order to get a little border, in which case an AnchorLayout would be just right. Or for arbitrary proportional behaviour, the FloatLayout is ideal.
Of course you can see there, the question really comes down to 'do you want layout behaviour', and if so you just pick the layout that does what you want. There's absolutely no limitation and rule, and it's in the design of kivy that you can combine behaviours like this to get precisely what you want.
(Suppose I'm only going to have a small padded background that I'll put a different colored gridlayout on, as in this question.)
In this case, an AnchorLayout seems ideal. This lets you set a padding for the child widget, but (by default) it's otherwise centered, so if you make your own AnchorLayout subclass with a background you'll get the border you seem to want.

Achieving a facebook-like modal dialog in GTK+ (linux)

Ideally, the transparent border.
Here's an example of what i'd like to achieve:
Notice the transparent border.
Now i suppose I could use cairo to create a rectangle with transparency, and put a borderless non-transparent window inside, mimic'ing that effect - which I would if i knew the window would have a fixed dimension. However, if the inner window grows, it'll grow out of the transparent rectangle.
How should one approach such task?
Making window frames is really the job of the window manager (at least under X11, don't know how it works on windows).
But have a look at the GtkBin, GtkBox or GtkMisc widgets. Pack the dialog inside it as a single widget, and use padding to give it a size. Read up on GTK+ drawing model. You will probably need to set a flag and define your own expose-event handler to re-draw your frame.

Categories