Window update consecutive - python

I have a question about the window.Update and window.read in PySimpleGui.
I see that when I use window.read, the programm didn't continue while i did not click on a button. But if I click on a button the window will do all the Update that i want until it will meet a new window.read or window.refresh.
My problem is that i want to do an window.update, stop during a few second, and do another winodw.update after. I try to use time.sleep but it didn't work it seems like all the line of programm is execute in same time.
So i want to know if it is possible to stop the programm during a few second between two window.read or if it is possible to "force" the window.read or window.refresh (skip them without click on a button).
Thank you in advance and sorry for my english who is probably bad...

Related

How do I use python to auto-answer a pop-up prompt in Windows?

I use a ticketing program at work all day every day. Every 5 minutes it produces a little pop-up window asking "are you still using the program?" and if you don't click yes in 60 seconds it logs you out and closes the program. Very annoying.
I want to use Python (or whatever else works, I don't really care about the language) to make a script that detects when this window pops up and automatically presses the "yes I am still here" button on that window.
I believe that I can locate the pop-up window using Python's subprocess library and win32gui library. That is still a work in progress but if you think you have a better method I'm open to suggestions.
Once I do identify the pop-up window, what would be the best way to "click" the "yes I am still here" button? It would be nice if I could do this in the background milliseconds after the window is generated so that it's almost like the window never existed at all, but it's fine if I need to bring the window to the foreground and use something like x,y coordinates to simulate a click.
Thank you for any help!
as #barmar said, https://pyautogui.readthedocs.io/en/latest/ will help you.
You can take a screen shot and scale it to get the image file of the popup. Then, you can use some python code to locate the image and press the button.
ButtonLocation = pyautogui.locateOnScreen('bttnScshot.png')
ButtonPoint = pyautogui.center(ButtonLocation)
button7x, button7y = ButtonPoint
pyautogui.click(button7x, button7y)
Thank you for your time, I am new to
stackoverflow. :)

tkinter button in a while loop, not using a mainloop: How can it be working with fixed intervals?

An answer to this question might be either about tkinter or parallel loops. I am not sure which solution will be the best. I need your advice.
I have a while True loop, which goes infinitely. Each loop takes around 5 seconds or more, and I wanted to create a GUI button (skip and stop_skip buttons). If the skip button is clicked by a user, it will skip the current while loop and move on to the next while loop until 'stop_skip' button is clicked. So, the skip button will be working as 'continue' in a loop.
Since each loop takes around 5 seconds, I want it to check the variable frequently in the loop. I found that tk.after() may work in every x milliseconds, and some people mentioned tk.update_idletasks() and tk.update(). I tried them, but they just show the box when the loop begins and freeze for the rest 5 seconds. If nothing can work like this (performing a function repetitively with intervals in a while loop), I will probably put if conditions multiple times during the while loop.
The script I want may look like..
show_tk_gui()
while True:
check_tk_if_skip_button_clicked(interval==1000) #if clicked, continue to the next while loop until 'stop_skip' button is clicked.
performing_5_sec_calculation()
Is there any way that can make this possible? Not using GUI option is also acceptable.

Preference window destroyed when closed - Glade, Gtk, Python

I am experiencing a problem with my program wherein when I close my preference window via the close button it will not reopen properly.
I open the preference window by going "file>preferences" which works just fine...
However when I close it via the close button in the top right...
It will no longer open properly. For the record the back button which I have connected to my close_pref_window function works just fine.
To open the window I go "file>preferences" which triggers a function that just preference_window.show_all() and to close it I call pref_window.hide(). I also have the delete_event connected to the same function as the back arrow so I don't understand why the one works and not the other. I am thinking that the close button destroys the window first and then calls the function... Any suggestions?
Thank you to #theGtknerd and #andlabs for your help. As theGtknerd pointed out the delete-event signal will continue to execute its default action unless your function includes return True at the end.
def pref_window_close(self, *args):
self.pref_window.hide()
return True
Thanks again for the help :)
(I apologize my question was answered a while ago, I was just mis-reading their comments :P)

Run function while Checkbutton is checked (Tkinter, Python 2.7)

This question is a follow up to:
Run long process continously using Tkinter (Python 2.7)
In the previous topic i asked about running a funtion continuously until a button is pressed. This funtion takes a long time to complete, and basically i wanted to stop the process (don't repeat the function) if a button was pressed.
I got an answer to my question, but i was wondering if this is possible using the Checkbutton function.
I know i can call a function using the Checkbutton (using command=[funtionname]), but what i need is a way to call a function continuously while the Checkbutton is checked, and stop when it's unchecked. Is this possible using tkinter?
Thanks in advance for any answers,
Harm
You mentioned that the process is a repeated process. You can just check the state of the button at every repeat with var.get() (assuming that the var is the variable of the checkbutton) and break out of the function if it is unchecked.
This is not a really elegant solution, and if a repeat takes a long time, the last "round" will still finish after the uncheck, so it is not immediate.

wait until button is pressed

I basically have questions being asked in a for loop and I'm trying to make each question wait for a response (aka a button to be clicked) before showing the next question..
I was wondering how I can get this done because the way I have it setup now is that each question will appear one after the other regardless of the response...
Note that a for loop won't let the gtk main loop do it's jobs and call the callback methods for the events you expect and your application will be unresponsive.
One way to do what you need is use a gtk.Assistant with one question per page in the assistant object and, possible, one last page with a summary of the results to the questions based on the expected responses.
Don't put it in a for loop, you need to show the next question as a reaction to an event.
I haven't worked with pygtk, but to make yourself an idea, if you had something like this:
for question in questions:
some_text_pane.set_text(question)
#wait until button pressed
you should have something like that:
question_pool = iter(questions)
def next_question(evt):
question = next(question_pool)
some_text_pane.set_text(question)
some_button.set_event_handler(next_question)
of course I don't know the GTK API, so don't take the method names literally.

Categories