tkinter with duration and start time for loop code - tkinter-button

How do I build a message box in tkinter with duration and start time for looped code.
I am not able to set a timebox in the message box and code that to direct a variable back into the code to start recording.

Related

Reset GUI values in Python 2

I have the following code, showing the segments that my question is related to. The program executes as expected for the first time when I run. The program gets user selected inputs from the user from a GUI. After the first run, I need to reset all the values and variables to their original status without shutting down the program and re-run. Specifically, the variable SaveFileName, is the variable that holds the file name from a PyQt LineEdit box and does not reset, even when the run button is again pressed (connected to the Run function shown below).
Is there an easy way to implement the reset in a short command? I know I can reset every value individually by putting a reset button and restore all the values to original one by one in the code, but I am looking for a simpler way if there is one. Any help is appreciated.
def Run(self):
global SaveFileName
SaveFileName==0
.......other codes creating and exporting data to excel based on
user selected options through a GUI
writer.save()
if SaveFileName==0:
self.Output_File_Window.setText("")
if SaveFileName!=0:
shutil.move(path_refs + "/TEMP_file.xlsx", SaveFileName)
SaveFileName=str(self.Output_File_Window.text())

How to 're-run' the mainloop in Tkinter

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.

Windows phone C++

I'm writing simple application for WP 8.1 using C++/cx. My problem starts when I'm trying to do something in some event. For example if I create simple button event "tapped" and I want to do something inside for example change the color of the button background, it doesn't execute in the correct time. I mean that for the code below it will first execute Somefunction() and then change the color of the button.Same happens for example when I try to show message box using message dialog and ShowAsync function.
but->Background = ref new SolidColorBrush(Windows::UI::Colors::Red);
Somefunciton();
You have the background change and the function call in the same function and that function gets executed on one thread blocking it. This thread happens to be the UI thread which gets blocked for the time of your function execution. So you set the button background but the actual change will be applied only when the UI thread could run the render function and it will be able to do it only after your function call ends.
So in terms of program execution the button background gets updated before the call to Somefunciton();. But visual changes are delayed until after the function call is completed so you might think that Somefunciton(); gets called before the background is set which is not the case.

How to display all images from directory one after another in qt,opencv

i try to make GUI Application in QT Creator.İ wanna display all images from chosen directory (a sort of slide show),i read QDir,QStringlist,QFileDialog class references but it doen't work.it shows only last image in folder.
for(int i=0;i<10;i++)
{
QImage image2(directory+"/"+fileList[i]);
ui->label_pic2->setPixmap(QPixmap::fromImage(image2));
//Sleep(550);
}
Sleep function only makes to load slowly not to show one by another.
First you need to undertand that GUI is only updated when you code is not executed and the application can process incoming events. If you create an endless circle your GUI will neved be updated. That's why you can see only the last image - because you don't let GUI to be updated.
You can force the application to process incoming events by QCoreApplication::processEvents(). In this case you will probably see quick flashing of images. But you will certainly need to make a pause after showing of each image. And your Sleep will probably work there, but during the pause your application will be freezed without being able to process the events.
That's why you have been suggested to use QTimer. It calls a slot in a certain amount of time. All the other time the application is processing messages and updates GUI and so on. When the slot is called you can switch label to show the next image. And this is exactly what you need.
Summary:
1. Create a QTimer, set interval and connect it to a slot, start the timer.
2. In the slot implementation read the next image in the list and assign it to the label.
Tip: To track what image is shown create a interger member variable. Set it to 0 when starting the animation, increase it in the slot.

Activate previous process on Mac

Is it possible to determine the previous active process to activate it?
Mac OS X / C++ / Carbon.
GetNextProcess() does not refer to Z-order of processes, but I need the real previous.
The original task is to bring the user back to their work when they closes my info window. Currently another window of my app gets the focus, if any, or there just no window with focus. It is unusable.
Update. Now I'm using the following workaround: 500ms timer watches for GetFrontProcess() which is not equal GetCurrentProcess(). Then calling SetForegroundProcess() for the last stored serial number.
You can get the zorder of processes from this place. Last process should be the one you are looking for. Or change code to read in reverse.