What it is the best way to make a chessboard for checkers using Kivy framework?
I have board.png, white.png, black.png, white_q.png, black_q.png files already. I wonder how to assign to each black tile on my board.png its own coordinate. Should I create 32 transparent widgets placed on black tiles of board.png or it is impossible? And what widget to use for 24 checkers? Any ideas or it is too complicated using Kivy and I should use tkinter?
There are many ways you could do this. It isn't complicated, it's very easy. The best way depends more on how you want to structure your app than anything else.
I wonder how to assign to each black tile on my board.png its own coordinate
Set the pos attribute of a widget to control its position, or better in this case use a layout that does what you want. For instance, adding your squares to a GridLayout with the right number of columns will have the right effect without you needing to worry more about positioning them.
Should I create 32 transparent widgets placed on black tiles of board.png or it is impossible?
I don't understand what you're asking here. You can make transparent widgets if you want but I don't know why you'd want to.
And what widget to use for 24 checkers?
The real question is, what do you want the widget to do? e.g. if you want it to display an image then inherit from Image.
Overall this answer is very generic because your question is very generic. I suggest that if you're stuck, try to ask a more specific question about a task you're struggling with, and give a code example showing where you are now.
Related
I still have been studying world of Kivy and I have encountered with question. I am designing an interface. it has to have an appearance of analog device with arrow and curved scale like old voltmeters were. Just to display a data on the screen. I've tried to use canvas, but I stacked with resizing of window properties. Built canvas object was either connected to specific size in px, or changed location on the screen in wrong way. So, I am curious, maybe here are some others ways to embed objects which were built in another 2d graphics library, I am aware of existence of 3d module vpython and turtle. Maybe we have some more?
Can anybody give me a hint? I would be very grateful
kivy, canvas
view of my prototype
You can use Image widgets combined with Button Behavior or ToggleButton Behavior to make buttons that look like almost any kind of button that you like. And you can make a curved scale as described in this question.
I am pretty new to Python and coding in general. I have been working on a program that is similar in nature to ms paint. So far, I've added the capabilities to create multi-colored rectangles, lines, ovals, and really any polygon.
I've been using the tkinter GUI. I've been wanting to add a fill command, but I'm kind of stuck as to how to start it. My idea for how it would work would be that it would check the color of the pixel the user is currently hovering over, then check up, down, left, and right for the same color in pixels. If it found that, it would change the color of those pixels (I guess by creating a really small rectangle object?). This would theoretically be able to fill an area. But, I really can't find anything on how to access the color of a pixel in tkinter.
I know the location is event.x and event.y for a specific event, but I can't find anything about pixel color. I don't really have any code written for it yet because I am unsure that tkinter can even access the color of a pixel and not just object colors.
Unfortunately, this isn't possible. I did some searching around, and found several other similar questions, but the general idea is that Tkinter does not support such a feature. It makes sense, considering that Tkinter is a GUI library.
I saw a suggestion somewhere, where an idea was proposed to create 1x1 rectangles using the Tkinter Canvas to basically mimic pixels. However, this method eventually leads into performance issues and lagging, so it's not really recommended either.
You may want to try exploring some other libraries to work together with Tkinter. You can keep the Tkinter GUI, but use an image manipulation library or something similar which integrates well with Tkinter, for the actual pixel drawing.
I've created a widget that uses the QGraphicsFramework to draw items to a canvas. Currently, I use one QGraphicsScene to keep track of my items and a QGraphicsView to visualize the items in the scene. I am using PyQt, but this is really more of a general Qt question.
This is what I have. It's one QGrapicsView and one QGraphicsScene.
What I want, where it's all drawn on one QGraphicsView, with three QGrapicsWidgets.
The first problem is that I don't know Qt that well so I am not sure if I understand the concepts correctly. It is my understanding that a QGraphicsWidget inherits from the QGraphicsItem so that I can add many of them to the same scene while still being able to handle all the events internally.
The problem with that is that the items inside each of these widgets need their own grid because items need to be at some given coordinates and have transforms inside the widget, etc. I am not sure how this could function, since there doesn't seem to be any such QGraphicsLayout that would allow this. This also kind of means each widget would need its own QGraphicsScene. I am not sure how to achieve this.
Can a QGraphicsWidget even have its own scene or does it have to access the shared main scene? If it had to access the shared scene, then each widget would need to be aware of where it was, which seems silly.
I don't need an implementation, just a clarification of how I would go about achieving this with QGraphicsWidgets. Or is my understanding of the QGraphicsWidget completely off?
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.
This is my first question ever so bear with me!
Currently in my program, I have a parent widget which acts as a canvas. The user can add or remove widgets to the parent at run-time. Those widgets are then given an absolute position, that is, they are not positioned by a layout. Once added, a widget can be moved around arbitrarily by the user.
I want the user to be able to select a group of widgets by dragging a box around them. I have already coded the part that displays the rectangle while the user is dragging. Now, I want to be able to retrieve all the widgets within that rectangle (region).
I am aware of the findChild() and findChildren() functions, and they indeed do return the children as they are supposed to. But what I'd really need is a way to limit the search to the boundaries of the region since there will most-likely be quite a lot of widgets within the 'canvas'. (There could be thousands of widgets spread over a very large area due to the nature of what I'm doing!)
Here is my question: What would be my best option? Should I just go ahead and use findChildren() and loop through the list to find the children within the region manually. Or should I loop through all the pixels within the region using findChild(x, y)? Or perhaps there is an even simpler solution that would speed up the process? Something along the lines of findChildren(x, y, width, height)?
Hopefully my question made sense. I tried to explain things as best as I could. Thanks!
If you had used QGraphicsScene instead of rolling your own, you could have used the items(..) methods to very efficiently find your children in a particular area.
It's only possible in QGraphicsScene because it uses a BSP spatial acceleration structure, so if you cannot migrate to QGraphicsScene in a reasonable amount of time - you are going to have write your own. It's not as hard as it sounds, I've written numerous bounding volume hierarchy structures and they're quite straightforward.