I am creating a Solitaire clone using Python's Tkinter window toolkit. My window contains a main canvas, and within the main canvas a series of widgets that inherit from Canvas that hold the cards. I have implemented a "Drag to Move" system where a user can click the mouse down to select a card in one of the inner canvases, drag it to a new canvas, and let go to place the card into the receiving canvas.
The Problem: I want to draw the cards in motion between the canvas on which they are drawn, and the canvas they are moving to, so the user can see them moving across the screen during the click and drag motion. When I try to draw cards in-between the canvases that I already have, they are always drawn behind, meaning I can only see cards through the padding around the inner canvases.
Here is an example where I drew several of them so the effect could be seen clearly, and the inner canvases are also clearly visible.
What I've Tried: I've tried to move the canvases back using Misc.lower(aCanvas), but i wasn't able to create the desired effect. I've also tried to design a custom overridden cursor, but it seems my cursor size is limited to 32px*32px, which is insufficient for the size of the card images I want to move.
My Question: How can I draw on top of a canvas that is inside of another canvas? If I can't, how would you solve this problem?
You cannot do what you want. Embedded widgets are always above the canvas items.
Why is it that you are embedding canvases insidebcanvases? Why not just use a single canvas?
Related
I have a GUI that I've made in tkinter using a canvas that has a bar along the left side and a bar along the top containing information. In the remaining area various rectangles are drawn corresponding to the information in those bars I described. The issue is, when you scroll away on the canvas, those events will leave as well.
Basically, I want to create a visual effect like position: fixed is in CSS where these bars on the side and the top stay in place relative to the rest of the canvas so that they don't move from their relative position while scrolling.
I tried making use of the scrollbar commands, but have had trouble making my own function there. I also tried to see if there was an event I could bind to the canvas to track the movement so that I could move the bars myself but I could not find anything.
There is no way to do this directly in the canvas unless you write the code to move the items in the top and left whenever the user scrolls. It would probably require a fair amount of work.
However, it's trivial to have separate canvases for the side and top that do not scroll, and a third canvas that has all of the scrolled data.
I was able to end up solving my own issue by adapting the solution from: How can I add Unscrollable Image to a frame/Canvas?
Simply put, I made my own yview and xview functions that would scroll my desired "bars" with the window by moving the objects.
Special thanks to #jasonharper for his help.
Before I say it, Sorry for my poor English.
I'm making an orbit simulation with vpython, because the earth science teacher asked me to.
The link below is the result of my work so far.
https://glowscript.org/#/user/sungho2574/folder/MyPrograms/program/2
Unfortunately, I can't watch the simulation and the graphs simultaneously, so I want to put two graphs side by side and put them right under the canvas. Also, I want to put "setting" next to the 3d canvas.
I tried various ways, but nothing worked.
And I found this vpython 6 link.
https://vpython.org/contents/new_features.html
In this link, I could find the GUI image that canvas and setting are located side by side.
But I also failed to work with it.
Can I put canvas or whatever freely in vpython 7?
Or in vpython 6?
VPython 6 ended many years ago. VPython 7 exists, but has the same syntax and capabilities as the Web VPython you are using at glowscript.org. From the documentation on canvases at
https://www.glowscript.org/docs/VPythonDocs/canvas.html
is this information on aligning canvases (and graphs):
align Set to "left" (canvas forced to left side of window), "right" (canvas forced to right side of window), or "none" (the default alignment). If you have a single canvas, setting align to "left" causes the canvas caption to be displayed to the right of the canvas. If you want to place a graph to the right of a canvas, set the canvas align attribute to the string "left" and the graph align attribute to the string "right". If the window is too narrow, the object that is on the right will be displayed below the other object. If you want to place a graph to the right of the canvas but keep the canvas caption underneath the canvas, create the graph first with align set to "right" and activate the graph by plotting something in it, then create the canvas without specifying its value of align. Another option is to specify align='left' for all canvases and graphs, in which case they will abut each other.
Here is an example (make the window wide):
https://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/HardSphereGas-VPython
I'm making a game with Tkinter canvas, and I'm planning to expand it (for UI) using grid.
Problem I'm facing is, that as it is, game window takes up bit more than the height of my screen. If I add anything on top, some parts will be completely off-screen. I can not change resolution of the canvas, as some parts move on pixel-basis. Thus I want to change size of the whole 'image' that Tkinter renders(canvas + other possible labels), that is the whole window.
Is there a way to do so?
window snapshot for reference
I have a QStackedWidget with a QLineEdit and a couple other widgets inside of it. This QStackedWidget is fairly dynamic - you can move it within its layout by clicking/dragging, change its current widget by right clicking it, etc.
I'd like to draw a simple, gray rectangle or a gray rounded rectangle around the QStackedWidget to let people know that the QLineEdit they're looking at is important. This drawn rectangle has to be able to follow the QStackedWidget so that it follows properly with the widget when I move it to other locations on-screen.
I've tried several approaches so far but they've all fallen short in some regard or another or it just wouldn't move with the widget. Can anyone show me how?
Depending on how your clicking/dragging is implemented, you should just be able to place the QStackedWidget inside another QFrame, or put a QFrame inside your QStackedWidget and put all the other controls inside the QFrame. QFrame's support drawing borders around them.
frame = QFrame()
frame.setFrameStyle(QFrame.StyledPanel)
frame.setLineWidth(2)
I am drawing inside a wx.Window using a PaintDC. I am drawing circles and stuff like that into that window. Problem is, sometimes the circles go outside the scope of the window. I want a scrollbar to automatically appear whenever the drawing gets too big. What do I do?
Use a wx.ScrolledWindow and set the size of the window as soon as your 'drawing go outside' the window with
SetVirtualSize(width,height)
If this size is bigger than the client size, then wx will show scrollbars. When drawing in the window make sure to use CalcUnscrolledPosition and CalcScrolledPosition
Here you can find some more information.