The Tkinter Text Widget Insertion Cursor - python

Is it possible to get the x y coordinates of the insertion cursor in a Tkinter Text widget? I'm trying to make a popup menu that pops up next to the insertion cursor.

The bbox method can be used to get the bounding box of an index. You can use that to get the position relative to the window. You can use the winfo method to get the x/y of the window.
Typically popups appear next to the mouse rather than the insertion point (though typically, right-clicking first sets the insertion point and then displays a menu).

Related

How to Reorder Elements Vertically Glade + Gtk?

I'm using Glade to design a UI, and I'm struggling to figure out how to reorder elements such that one element is on top of the other vertically. As an example, I added a draw element after a slider, picture, but I want to still be able to touch the slider through the draw element. Beyond reordering things manually in the XML/.glade file, how would I move things around such that the draw element gets "drawn" first with the slider on top of it?
Die clarification. So far i See from the picture (I dont understand the Text), you create radio buttons and in one type of it, you want to dynamically letting a new window area appearing with a slider in it when clicking?

Finding position of viewport in Selenium Python?

I need to find the position of the top left corner of the viewport in Selenium. I know we can use drive_get_window_position() to get the window position, but I need just the position of the part that renders. Is that possible?
The use case is that I am attempting to use Selenium to get the coordinates of an element, and need to move the cursor to it. Since Selenium only moves the virtual mouse and not the visible cursor, I am using pyautogui to move the cursor to absolute coordinates.
However because the browser position affects where the absolute coordinates should be, I need to know where the viewport is so I can offset appropriately. Using the get_window_position() works for x coordinates but not y coordinates due to the various menus and toolbars.
location_once_scrolled_into_view¶
THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where
on the screen an element is so that we can click it. This method
should cause the element to be scrolled into view.
https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html#module-selenium.webdriver.remote.webelement
Returns the top lefthand corner location on the screen, or None if the element is not visible.
Eg:
e = driver.find_element_by_xpath('//html')
print(e.location_once_scrolled_into_view)

Python - TKinter - Moving shape on canvas with a mouse

I need to find a way to code the following
1.there's a geometry object that contains an array of points that are then drawn on a canvas widget (got this covered)
2.when you left click on the canvas it checks if you clicked withing a certain margin of an existing point and if that's true a point in the array is selected (got this covered in terms of searching for the point and selecting it)
3.Once selected the point will follow the mouse until the mouse button is released.
Using the Motion event on it's own doesn't seem to work as it seems the function is called over and over while the button is pressed. So I'd need to trigger the search function when the button is pressed them the move function when the button is held.
I'd be grateful for pointers.
Thanks to Dan Getz I did the following:
-bind the point selection to select point and store index in self.selectedPoint
-bind move function to using the self.selectedPoint to indicate the selected point in the array, then passing the events x,y coords to the array as new coords for the selected point
-bind the clearSelected function to to set the self.selectedPoint to -1 thus clearing the selection
The problem I'm still having is that when moving the point I update the screen while the mouse is held which produces quite a bit of flickering. I'm wondering if there's anything I can do to prevent that.

How to find the element text which are not visible on screen using pywinauto

I have a grid with horizontal and vertical scrolling and I want to print the complete data of this grid but I am unable to get as it is not visible onscreen.
Finding elements via scrolling doesn't provide a proper solution for the child elements. Any suggestion on how I can achieve this for the grid below?

Can I draw on top of a canvas inside of another canvas?

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?

Categories

Resources