I am trying to capture text from a Text Input box and fire off a function after the text is inputted. Only problem is the event is fired everytime a character is entered. I would like the event fired after all characters have been entered in the text input box. How could i delay the firing until all characters have been entered?
I tried to override the on_text method but did not solve my problem as it is this method that is being called 20 times. I also tried putting in a sleep in the on_text but it just buffered the responses and still fired 20 times.
Do exactly what you're already doing, but have the function you're calling check if whatever condition you're after is met. For instance, if you want to call it after 5 characters have been entered, check the length of the string.
This seems an awkward way of working though, are you sure you want to check after every character rather than, say, wait for the user to press enter?
Related
I am trying to make a text box in allegro and need a way of getting the ascii keycodes from the key presses. The ev.type == ALLEGRO_EVENT_KEY_DOWN does not always work. I have tried getting the event to work faster but it is still slow.
If there is a way I could make this into a function that could give the Ascii char of what ever key is pressed, it would be great. (I have been looking but I cant find something easy and fast for the source code that I am using)
Perhaps you are looking for an ALLEGRO_EVENT_KEY_CHAR event type. These events are generated every time a character is typed on the keyboard, or auto-repeated because the key was held down long enough. In other words, while ALLEGRO_EVENT_KEY_UP/DOWN events correspond to the keyboard state, ALLEGRO_EVENT_KEY_CHAR events correspond to the character input buffer state.
I'm making a text-based game. I'm trying to have a little "health bar". When the user hit space, and when the button is pressed it will make health go up by 5, but while this is also happening I need something to be running in the background that is doing the same as if it was a AI, except I want it to subtract 1 every time and for it to only hit it once every second.
I tried getch(); the most but the problem with that is that it stops everything and waits for the user to use a input so nothing can be going on in the background that is subtracting health.
If you could use the _getch(); command in any way to accomplish this, because I already know how to use it well.
I've been asked to make a Chat program using Tkinter. For the final part, I'm supposed to have the Chat window open, which has one Entry field, one Button (SEND) and a Text Widget to display the chat log. This is my first week learning Tkinter, and I've been told in class that the mainloop() is an infinite loop as long as the user doesn't close the window or write root.quit(). So in the chat window, I'm supposed to check for new messages every 10 seconds. Is it possible to do that in the mainloop()? If yes, please let me know how, because I have no idea how that can happen since the stuff before the mainloop() is read only once. For example, something like a print statement is printed only once, even though the mainloop() is an infinite loop.
You can call the after method of the root window to call something in the future. If that function itself calls after, you can set it up so that your function runs every 10 seconds forever.
def check_for_messages():
<your code here>
root.after(10000, check_for_messages)
Call that function once before calling mainloop() and it will run every 10 seconds for as long as mainloop() is running.
I have a trackbar control in my app and I want to do something when user starts scroll operation (when he clicks on the trackbar's thumb). Since WM_HSCROLL doesn't notify about such event, I was wondering how do I get to know when user starts scrolling. I'd like to avoid processing SB_THUMBTRACK request since thay would mean I'd have to process it all the time when user's scrolling, and I just want to know when he starts doing it.
Just process TB_THUMBTRACK and ignore all subsequent TB_THUMBTRACKs until you get TB_ENDTRACK. That's roughly 5-9 lines of code.
For trackbars you also should use the TB_* (trackbar) constants and not the SB_* (scrollbar) constants even if their respective values are the same (e.g. SB_ENDSCROLL == TB_ENDTRACK == 8, SB_THUMBPOSITION == TB_THUMBPOSITION == 4).
I know what I'm asking is contradictory
SendNumber(LastNumber);
Sleep(2000+(level*100));
SendNumber() is a function that sends LastNumber to an edit control with WM_SETTEXT. What I'm trying to do is sleep the program for a moment, leaving the text on the edit control, and after the time ends remove this text.
My problem is that Sleep() stops WM_SETTEXT from typing the text, so the program waits 2000+(level*100) milliseconds and then the text appears on the edit box.
Is there any way to stop the program from running forward until the time ends, but without stopping all the window activity?
Look at the SetTimer function. This will send your program a WM_TIMER message after a specified period, which you can then handle.
Add
UpdateWindow(your_edit_control);
just after SendNumber.