Python Tkinter Restart the program without killing it - python

I have one simple question. Is there a way to put some button that will when pressed put everything as it was in moment I started program. Thanks.

Related

WxPython exit button doesn´t always works

I am using a code designed by another person in MAC OS. I am using Windows instead and have slightly modified it, but the problem comes when using the GUI that is created.
I have already dealt with a similar issue with a slider. Once I pressed the slider, I couldn´t release it or press another button. I was forced to quit the GUI and start again. I solved it by changing the event command from EVT_COMMAND_SCROLL to EVT_COMMAND_SCROLL_THUMBTRACK. However I did not understand why it worked in MAC OS and does not work in Windows.
Now, I want to close the GUI with the typical cross inside the red button in the right corner of the window. I can do it if it is the first order I do in the GUI. If I first press any button or slider, the exit button does not work.
It made me consider if a major problem is hidden in the code which I am not seeing. I am new at wxPython, which is the module used in the code.
I just ask for your opinion and hope it is a basic error.
Thanks very much

How can I terminate Python Script with particular 'if' conditions that does not affect Tkinter GUI?

I have created GUI using Tkinter and one main script to run. I have some conditions in the main script. if conditions are not satisfied I want to terminate the further execution but keep the GUI active and open. Currently I am using sys.exit() to terminate the script but it is also affecting GUI and Gui goes in not responding mode right away.
for all false conditions in the main script, I am using error dialogue box(messagebox.showerror) on screen and I want to terminate the script once I click OK on the dialogue box.
Could anyone please help me get this working?
Thanks in advance.
i tried what furas said and it worked.
"if you run some function then use return to end this function. – furas Jan 24 at 13:38"

Want Clarification for Program Loop (Python)

So I was wondering if someone would be able to help shed a little light for me on something I am working on in Python.
I am creating a program with a Tkinter GUI interface that interacts with a Serial device, and an ADC chip to measure voltage. I want to make sure I properly understand how I'm building the main program loop to keep everything running smoothly. I'm going to lay out how I think the program should run, if anyone has any corrections please throw them at me.
Program is run, GUI Interface initializes
User presses a button
send signal of button through serial
measure/display voltage levels
periodically update voltage display
if button is pressed, return to step 3
Now I know to run my Tkinter GUI I set up mainloop() as the last line of code. Now my question is simply, is that all I will need? Will mainloop() continually update while it waits for another button press, or will I essentially have to creatre an update method that cycles through everything until another button is pressed?
Will mainloop() continually update while it waits for another button press, or will I essentially have to creatre an update method that cycles through everything until another button is pressed?
Not all. That's why you are using tk.Tk().mainloop(). tkinter does this for you. All you are expected to do is implement the functionality that should happen when your button is pressed. tkinter will listen for the button press.

Python another option to tkinter label counter

I have a program that I'm currently using tkinter to pop up a window and use the root.title of the window as a counter. I call this program through subprocess mutliple times, aka multiple windows pop up and display that I only have to look at the counter to see how long before each of the programs is finished running.
I want to know how long before each and every process is finished. Doing a bit of testing I don't believe using subprocess it will report back to IDLE and show a counter using print(). At least it doesn't appear to be doing so right now for me.
Is there any way of accomplishing this same task without using tkinter?
Below is the link to the other open question right now that I'm currently using to open the tkinter window that closes on me unexpectedly. I'm not completely sure when a windows closes if the whole program stops running or if just the windows closes. Hence why I want the counter...hence why I have always been using a tkinter window as I don't know of any other way of doing this that serves the same purpose.
I want the counter so I can tell the program was finished if my internet connection gets dropped. I don't have internet access at home so I'm always using free-wifi which quite often has timeouts on it. I want to know for sure whether the programs have finished running or if I got timedout and need to rerun the program.
Python program terminating unexpectedly

KUbuntu, Python and libtcod - console_is_window_closed not working...?

I've done a reasonable amount of coding with the libtcod library, both the C# and python wrappers. My current setup is KUbuntu 14.10, python 2.7.8, and libtcod 1.5.2.
I've made a few programs that work fine, but the latest I've just started doesn't seem to want to allow me to close the console window.
I can send a CTRL+C from the console that I run the program from, and it will close, but, no amount of clicking on the window's "x" button, or Alt+F4s seem to work.
My code is as follows:
'''
justclose.py
'''
import sys
import time
import libtcodpy as libtcod
libtcod.console_set_custom_font(b'lucida12x12_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(50,50, "The ever-present window", False)
libtcod.console_flush()
while not libtcod.console_is_window_closed():
time.sleep(1)
sys.exit
When I run the program, the console comes up, as expected, and sits around waiting for console_is_window_closed to return true, which it never does. I'm not sure where the problem lies. I can run other programs that use the same initialisation code, and same while loop and which respond just fine to me clicking the close button on the console window.
I've tried looking through an strace of the process, but, I'm not sure I'm up to the task of deciphering it. Nothing looked immediately out of the ordinary.
I'd like some advice on how to track down what's going wrong. Thanks.
EDIT: specifically, I'd like to know how I can check that the close window event is propagating at all, and if so, how far, where it's getting trapped/ignored, that sort of thing. When I run through strace, I see absolutely nothing happening when I click the close button. Is there some better way to debug this?
Replace time.sleep(1) with libtcod.console_check_for_keypress(). When the program sleeps 1 millisecond for each iteration, the program can not respond when you press X. It exits when you press CTRL+C because the program receives the SIGINT signal and it exits immediately. Replacing time.sleep(1) with libtcod.console_check_for_keypress() makes the program check the key pressed on the keyboard, if there is one. That way, the program doesn't block the execution.

Categories

Resources