2d graphics in Python Kivy, advice is needed - python

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.

Related

Creating a "Fill" command in tk inter

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.

Checkers board in kivy

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.

Is there a way of drawing non-canvas lines in Tkinter?

Hi !
I've been looking all over StackExchange and some other forums for an answer to my question but I couldn't find anything relevant, so here I am, posting my question.
What I'm trying to do is to draw lines that are on the same layer as other Tkinter widgets. I'm currently coding an interface where certain widgets need to visually connect to each other (NodeBox style or Quartz Composer style).
Shows the connectors (noodles) present in Quartz Composer. (I'm not necessarily looking for curved lines, straight is more than enough.)
The problem is that it is too complicated to use the canvas widget (I will be using a lot of widgets so embedding all of them into the canvas is not really an option I think). I'm looking for something similar to the separator widget but allowing for diagonal lines and defined by coordinates. I'm thinking of creating a custom widget that does this but I'm not sure where to start. An other solution may be to have a transparent canvas right over the non-canvas widgets but that would complicate the mouse click events a lot. I don't know what option would be the best.
Any thoughts on how I could accomplish drawing lines out of canvas widget? (Or on how I can create a custom widget that does this?)
Your only reasonable choice for drawing lines is the canvas. Without the canvas you can simulate horizontal or vertical lines using a separator and place, but you can't do diagonal lines.

How to drag objects around in a Gtk.Fixed widget using mouse events?

I have a custom object(a small circle) placed at some point inside a Gtk.Fixed() widget .Is there a way to drag this object around using the mouse. I am not able to map the Mouse Press/Release/Motion events to make this work.
I would prefer solution in Python using PyGobject but any other language will do also be fine if explanation is provided
More Details:
I am trying to make a font editor where these objects I mentioned above will be the control points of the bezier curves in the Glyph outlines
Here is an image of the concept design:
https://github.com/sugarlabs/edit-fonts-activity/blob/gh-pages/files/img/wireframe_concept_01_first_prototype.svg
I need to able to move the points shown to edit the outline of the letter shown
GtkFixed is not designed to do drawing work. It's made to locate widgets (such as buttons and such) on a fixed grid (รก la Windows).
If you would like to move elements of a drawing, have a look at eg. GooCanvas. Each element on a goocanvas can have events connected, which can then be used to move it around. You can even use CanvasGroup to group primitives (circle, rectangle etc), and move them together (even change other properties such as color, linewidth). The toolbox actually contains curves etc. It's easy to create a 'handle' using a small rectangle.
Here's an example of a simple goocanvas program, and you can find download links, references manuals and other useful stuff here.
I don't know if this is a tool you need, or just a learning exercise. If the former, then do have a look at FontForge, an open source font editor, and incredibly versatile.

What is the best practice to overlay a Phonon.VideoWidget?

The last couple of days I have tried to find a working solution to overlay a Phonon.VideoWidget with a simple QLabel. Sadly I wasn't able to find a working solution.
Here is what I have tried:
Parenting. I tried the "normal" parenting stuff addressing the QLabel to the VideoWidget. Result: The label does not show up at all.
QStackedLayout. As suggested here: http://www.qtcentre.org/threads/31490-Overlaying-Widgets-on-top-of-VideoWidget. Result: Label is shown but always behind the video
GraphicsView. I tried a lot here as it looked like the most promising, but at the end the CPU load was just too high so the video did not play back. Setting the view's viewport to QGLWidget did not solve it. Result: Overlay works but video does not play caused by high CPU load.
Subclassing the VideoWidget. As mentioned here: https://wiki.qt.io/Overlay_widget_for_Phonon_VideoWidget. I took the same approach to create the overlay. This works just fine after all, except for the moveEvent. It does not look nice if the label is realigned after moving the widget has finished. Is there a way to update this already when moving VideoWidget?
I really hope someone can help me here (I use PySide but examples in C++ should work as well) or give me a pointer on where to look. Please let me know if I should share some code snippet to reproduce.
The best you can do is creating a new window that floats above your video widget. For example create a parentless QLabel and make sure that it moves in sync with your main window.
label = new QLabel();
label->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
In your QMainWindow subclass, override moveEvent and resizeEvent and do something like:
label->move(mapToGlobal(QPoint(0, height() - label->height())));
This keeps the label in the bottom-left corner, change it to fit your needs.

Categories