wxPython: Find the focused wxTextCtrl? - python

I am new to wxPython and trying out some examples. I am using wxFormBuilder to create a simple GUI with many wxTextCtrl. I want to determine the current location of cursor, which is in one of those wxTextCtrl and do some operation. How do I do this? Please help!

Try using the wx.Frame's FindFocus() method. That should return the widget that has focus.
See also:
wxPython: How do I find out which widget has the focus?

Related

How to disable window movement in tkinter

Quick question, is there any way I can prevent a Tkinter window from being moved by the mouse? I couldn't seem to find any answers on google so I'm asking my own question. Thanks in advance!
A way to do this is by Using
Overrideredirect(1)
However this will ignore completely all window functions from the os window manager.
If you want the rest of the functions you will have to create a new fake window title bar yourself and assign all the functionalities you need (window close, minimize, maximize)

Place a button inside a grid

In a gui I have a grid. In this grid each row represents an order. To the right of each row, I would like to place a 'cancel button'to cancel the order. When new rows are added this should automatically come with a cancel button.
I did some seaching but apart from this FAQ-question which states that you have to design something yourself (did not help me much). Al other material was based on usage of Tkinter which I do not want to do.
So Two questions:
(1) Does anyone know of a way to place a button in a grid cell in wxpython?
(2) If not, does anyone know of a solution for my requirement?
Thanks,
Django
There isn't really a "built-in" way to do this. You would need to create a custom Renderer. According to Robin Dunn (creator of wxPython) in this thread, you could create a button using wx.RendererNative.DrawPushButton.
I would also recommend taking a look at the wxPython demo as it has some other examples of custom renderers too.

How to Build a Custom wxPython Custom Menu Widget

Background:
In recent days I've been experimenting with building many ordinary widgets from scratch in wxPython using the PyControl method of building custom controls as a personal challenge. However, I've hit issues when building a custom menu widget. By this I mean I am envisaging a button that when clicked on yields a drop down menu of options/commands etc.
Question:
What is the best way of achieving a completely custom menu widget in wxPython? Ideally I'd like to use only original code (i.e. as much as possible handled directly in the code). An ideal answer would include a runnable code snippet if possible.
Thanks for any help!

Canvas Selection Tool? wxpython

Is there a way to make a canvas selection tool in wxpython?
LEFT BUTTON PRESSED:
When the left button is pressed start drawing rectangle and update it until the user releases the left button.
LEFT BUTTON RELEASED:
Finish drawing rectangle
It is something similar that you would see in a paint program.
If possible please provide an example.
Thanks.
You could try to do it with wx.Overlay
You have an example of a drawing canvas in the source code downloads from wxPython in Action.
This is a canvas for freehand sketching. You can start from there to expand its functionality.
The simpler example is example1.py from Chapter-06 folder. There are several other examples in the same chapter with increasing functionality.
For an example of a drawing tool selector and how to move and modify the objects selected and set in a frame I would recommend to look at the code of the wxglade GUI designer.
The Whyteboard application has a selection tool that you could use for inspiration. You can get it here: http://whyteboard.org/ It's written in wxPython. By the way, the wxPython mailing list is a great place to ask questions too.

Make Spinctrl selected when activated in WxPython

I have 4 spinctrls in my app. When I click on them, I want all their
content to be selected instantly. And another thing is, I need to make
them tab traversal. Can you help me with some sort of code to do this
task?
Thanks in advance.
You need to catch EVT_SPIN or EVT_SPINCTRL and in your handler, you can select all the values by calling each of the control's GetValue method. In the wxPython demo, it seems to support tab traversal. I'm not sure what's going on with yours. Did you try the FloatSpin widget as an alternative?

Categories