What is the meaning of & in button Name parameter? [duplicate] - python

This question already has answers here:
Creating menus using wxpython
(2 answers)
Closed 7 years ago.
When I create a button in wxpython I can do:
self.all = wx.Button(self, -1, _("&ALL"))
or
self.all = wx.Button(self, -1, _("ALL"))
both generate a button named ALL
So, what is the meaning of the & in the name parameter?
ducomntation doesn't specify anything about it.
the question here is similar but it's not the same. The solution there is set focus. while you can set focus to a menu, you can not set focus to a button.

I think the & indicates the keyboard shortcut that can be used to activate the button. So &All means you can press A instead of clicking on the All button.
You can put the & anywhere in the label, the character after it becomes the shortcut. For instance, one of the stock labels on the documentation page is:
wx.ID_CUT 'Cu&t'
This means that T is the shortcut for the Cut button.

I guess (keyword: GUESS) is since you are building a GUI, you may want to consider internationalisation link. This is done by searching through your *.py file and search for any string that could be replaced to a different language, using UNICODE. By having & in front of the string displaying your button, you can easily search for it using, maybe, gettext.
Again, a guessing answer :)

Related

How to check if a window is showing [duplicate]

This question already has answers here:
Can I detect if a window is partly hidden?
(2 answers)
How to determine if any part of the window is visible to Screen?
(1 answer)
How to get only the visible part of a window (Windows, gdi32, user32, etc)
(2 answers)
Closed 8 months ago.
I want to get a window's clip box so I can detect if the whole window is displayed.
package: win32gui
I know that IsWindowVisible() from the Windows API will return true if a window is NOT minimized, but it won't detect if the window is hidden behind other windows.
I also know that in C++, I could use GetWindowDC(); GetClipBox(); ReleaseDC(); to get a RECT struct with the coordinates of the smallest bounding rectangle of the window (I got this from another post on StackOverflow, but I haven't tested it).
In Python, I can use:
# That just returns a window by the title
handle = getWindowByTitle("Skype") # "Skype" is just an example
winDC = win32gui.GetWindowDC(handle)
# this function doesn't seem to exist/be implemented in win32gui
win32gui.GetClipBox(winDC, '''This also needs a RECT struct''')
win32gui.ReleaseDC(winDC)
How can I use GetClipBox() in Python? Or, is there any other way to check it?
I would like to not use any other package, because I want my app to have as few dependencies as possible.
I have also heard of ctypes, but I have never used them. I am not sure how it works, and/or if it can help here.

Single tab to display multiple different widget panel options [duplicate]

This question already has answers here:
PySide switching widgets with events?
(2 answers)
How to change UI in same window using PyQt5?
(1 answer)
Closed 2 years ago.
The project is based in Python 3.7.
I'm working on a project that requires the use of the tabs widget. Lets say I have two tabs. On tab 1 there is a drop down menu with two different options. I need these two options to determine what will be displayed on tab 2. For example, if option 1 on tab 1 is selected then tab 2 could show a simple list or, if option 2 on tab 1 were selected then tab 2 will show a check box.
My naive thought it I might be able to create three different widget panels, each with the required widgets and displays for tab 2. Then a simple if/else check could determine which option number is selected and thus which widget panel to display can be selected. This is a guess at best though and I'm not sure how one would implement this.

Is there a way to automatically select an Entrybox in tkinter? [duplicate]

This question already has an answer here:
Set default caret position inside entry widget in Tkinter Python
(1 answer)
Closed 3 years ago.
My GUI is structured such that I have a main class, and each page of my GUI, of which I can navigate between, is instantiated whenever I call it. One of my pages has an entry box, but i have to manually move my cursor and select the entry box to begin typing. Is there a way for the entry box to automatically be selected when I call that page?
Seems like an interesting problem
You should use focus().
For Example, if your entry widget is e. Then use e.focus().

Python open window and set parent insensitive [duplicate]

This question already has an answer here:
PyGObject and glade send window to the front
(1 answer)
Closed 8 years ago.
I am currently building an application with python 2.7 with Gtk3+.
I want to open a window on top of another window. If the second window is visible, the parent one should not be clickable.
So the behaviour should be the same like opening a dialog window.
What is the best way to achieve this?
You need to use the property window.set_transient_for(parent_window)
This post may help you if you are using glade.

Generating an event when the cursor moves in Tkinter [duplicate]

This question already has answers here:
binding to cursor movement doesnt change INSERT mark
(2 answers)
Closed 8 years ago.
I'm making a basic IDE, line numbers are going to be similar to IDLE, but I don't want to bind each possible key to an event which changes the box with the current line/col in it. Is there some kind of "on change", or "one cursor move" event build into Tkinter, or more specifically, ScrolledText. If there isn't then if anyone can point me in the right direction that would be fantastic.
Thanks!
There's nothing built-in per se, but what you want to do is possible if you're willing to be creative.
At it's core a text widget is a tcl command, and this command is called whenever something happens to the text widget: text is inserted, deleted, the cursor changes, etc. The nature of tcl is that we can replace this command with our own command. And since we can do that, we can detect certain changes, and call our own function before or after.
It sounds complicated, and it is. On a positive note, it's foolproof once you have it working, and it means you don't have to do any custom bindings. To see a complete working example, see this answer to the question binding to cursor movement doesnt change INSERT mark.
The scrolled text widget is just a thin wrapper around a regular text widget, so this answer will work with just a tiny bit of tweaking (you'll need the reference to the text widget used by the scrolledtext widget). The wrapper is so thin, however, that I recommend not using it since adding scrollbars to a text widget is trivial.

Categories