Opening up a Drop-Down-Menu Tkinter - python

I have been implementing in a drop down menu (offically called a "Tkinter.OptionMenu") inside my application, that once clicked open will allow users to skip to certain parts of the form (like skipping to a certain chapter of a book/play). I want to be able to OPEN that drop down menu on an event i.e with code however as much as i have searched, it seems the very best i can do i to do a .focus_set() which is better than nothing, but all it does it place a faint outline around the widget. I would like it to fully open it up, just as if the user had clicked on it.
I'm pretty sure that i'm missing something simple, but help would be appreciated :)
Edit: Yes, i do have good reason to programatically open it, and even if i didn't it would still be nice to find out. I do not need access to the functions the list gives, but rather, i need the user to pick something from that drop down, and so i would like to open it for them

Related

Code to listen for changes in a pywinauto Listbox

I'm using pywinauto to interact with the window of an old game - specifically the dedicated server GUI. I've been able to connect to it with:
app = Application(backend="uia").connect(path=r"C:\Program Files (x86)\___.exe")
Using a loop, I'm able to read each line in a Listbox in a specific window using:
for i in dlg.ListBox.descendants():
print (i.window_text())
The Listbox behaves as like a console output area and I've also been able to write commands to the Edit (input) field which appear in the Listbox.
All of this is great considering I didn't think it would be easy at all!
However, the last part of what I'd like to do is proving more difficult...
I want to listen for changes in the list box so I can react to them and write different responses back into the Listbox. So for example, when a player joins the server, I want my code to know that a new line has appeared in the Listbox (so I can write a custom welcome message to the Edit field).
I have tried to look at listener scripts but I feel a bit out of my depth and can't seem to find a simple code example that could help me accomplish this. Does anyone have any ideas where I could look or what I could use?
Even better... would anyone be able to provide some sample code for me to re-work?

Dynamically indenting and highlighting words in tkinter textbox

I recently made a simple notepad-like text editor but now I want to implement things like syntax highlighting certain words and automatic indentation as you type. How could I do this dynamically as the user types. So far everything I've done is event-based so I'm guessing I need to have some sort of loop that constantly checks the contents of the textbox as the user is typing? Is tkinter not suited for this? Appreciate it if you steer me in the right direction as to how I can implement this.
Tkinter is quite well suited to this sort of thing. It's possible to make a very smart text editor if you're willing to put in some effort.
This answer shows how to get the text widget to fire an event whenever something in the text widget changes. It's a little complicated, but fairly foolproof.
If you want something simpler, you can simply bind on <Any-KeyRelease> which will fire an event whenever the user releases a key. You can then use the information in the event object to decide what to do. It won't handle the case where you cut and paste with the mouse, for example, and your binding will fire for arrow keys and other non-inserting keys, which is why I recommend the more complicated solution.
This answer shows an example of using a binding on <space> to do do a simple spellcheck, and also shows a fairly simplistic implementation of a toolbar with a "bold" button.

Textedit + CombBox + pyqt4

I need help with a program. I need use a texedit + combobox.
I need open a txt and set it to my textedit ( i've alredy did it)
than i need use my cursor, to get some word, than use a specific thing in my combobox... for example Polarity, this box have only numbers, 1,-1,0
and with a button, i need save it on a new txt or other archive.
I have a menu bar with open,new,save and close. I can open a file modify it and save, but i want to save with a buttom, the word that i underline(with cursor) + the number i selected and saved for that word.... it's possible? how i can do it?
It's better using table widget? im new using pyqt4 :(
please help me... i dont know how to do this thing ..
The best way to get started with PyQt4 is to look at some working examples that are similar to the application you want to write. The PyQt4 source has lots of these - download it from here, and have a look in the examples directory.
In addition to this, there are numerous tutorials available that will help get you started. A good place to start looking is the PyQt4 wiki.
Once you've worked through a few tutorials, you will probably be able to achieve what you want quite easily. And if you get stuck on something, you can always come back and ask about it on SO (just make sure to ask a specific question, and post the code that you have so far).

GUI programing with WxPython, drag and drop problems

I would like to begin by thanking you all for taking time to try and help me out. For my dissertation project I have decided to make a network topology program (similar to somthing like Cisco packet tracer or GNS3) My program also has the added benifit of a subnet calculator. I have the basic layout complete and I feel rather confident that I will definitly complete this program, but due to a lack of information on the web regarding wxPythons drag and drop feature, I cant find anything which is specific to what I need.
What I would like is a column, or some sort of area within my frame that the user is able to select things like routers, switchs, servers, IP phones and hosts etc etc. They then have the ability to drag these network items from the column onto the topology area. They should then be able to double click the item and a new form pop up. the user can then give the item an ip address etc etc.
Please do not think I am asking for someone todo this for me, I am simply wondering if someone could help me out by suggesting wxPython tools that could suit the needs that I have stated. If anyone has had experience with this kind of thing then please could you shed some light on it for me. I would be more than happy to produce my code online if you should need to see it.
Thank you in advance for your time.
There are Drag and Drop examples in the wxPython demo. Also see http://wiki.wxpython.org/DragAndDrop or http://zetcode.com/wxpython/draganddrop/
Depending on how you're displaying your information in the topology area will decide how to make double-click function. For the most part, you either bind to the widget's double-click event or it's selection event and act accordingly in its handler to display the dialog or frame. When you can tell us what widget we're double-clicking on is when we'll be better able to answer that question.

Python widget/cursor detection?

Beginner python learner here. I have a question that I have tried to Google but I just can't come up with the proper way to ask in just a few words (partly because I don't know the right terminology.)
How do I get python to detect other widgets? For example, if I wanted a script to check and see when I click my mouse if that click put focus on an entry widget on a (for example) website. I've been trying to get it to work in Tkinter and I can't figure out even where to begin.
I've seen this:
focus_displayof(self)
Return the widget which has currently the focus on the
display where this widget is located.
But the return value for that function seems to be some ambiguous long number I can't decipher, plus it only works in its own application.
Any direction would be much appreciated. :)
Do you mean inside your own GUI code, or some other application's/website's?
Sounds like you're looking for a GUI driver, or GUI test/automation driver. There are tons of these, some great, some awful, many abandoned. If you tell us more about what you want that will help narrow down the choices.
Is this for testing, or automation, or are you going to drive the mouse and button yourself and just want something to observe what is going on under the hood in the GUI?
>How do I get Python to detect other widgets?
On a machine, or in a browser? If in a machine, which platform: Linux/Windows (which)/Mac?
If in a browser, which browser (and major version)?
> But the return value for that function seems to be some ambiguous long number I can't decipher
Using longs as resource handles is par for the course, although good GUI drivers also work with string/regex matching on window and button names.
> plus it only works in its own application.
What do you mean, and what are you expecting it to return you? You should be able to look up that GUI object and access its title. Look for a GUI driver that works with window and button names.
Here is one list, read it through and see what sounds useful. I have used AutoIt under Win32, it's great, widely-used and actively-maintained; it can be called from Python (via subprocess).
Here are comparisons by the author of PyWinAuto on his and similar tools. Give a read to his criticisms of its structure from 2010. If none of these is what you want, at least you now have the vocabulary to tell us what would be...

Categories

Resources