According to the example from:
I'm running python script that shows Tkinter frame by invoking:
startx ./script.py
... when the script is done, it exits with:
root.destroy() # Tk() from Tkinter
sys.exit(0)
... however X server seems still to be running (blank screen is displayed and I have to use Ctrl+C to get access to the console back).
How can i make xserver stopped immediatelly when following application exits?
EDIT: I've noticed that if i didn't use MyThread (but e.g. timer handler method), closing X windows session works fine. Also this script finishes properly when run (tested) on Windows.
Code with issue:
#!/usr/bin/env python
import sys
import threading
import time
from Tkinter import Tk, Frame, BOTH
SCREEN_RES = "1024x600"
DELAY = 1000
TK_ROOT = Tk()
class MyThread(threading.Thread):
def run(self):
try:
print "Entering MyThread..."
time.sleep(3)
print "Exiting MyThread..."
TK_ROOT.destroy()
sys.exit(0)
except KeyboardInterrupt:
exit()
# noinspection PyAttributeOutsideInit
class SysInfo(Frame):
mt = MyThread()
def __init__(self, parent):
Frame.__init__(self, parent, background="gray")
self.parent = parent
self.init_ui()
self.after(DELAY, self.on_timer)
self.mt.start()
def init_ui(self):
self.parent.title("SomeFrame")
self.pack(fill=BOTH, expand=True)
def on_timer(self):
print("Timer fired.")
self.after(DELAY, self.on_timer)
def main():
TK_ROOT.geometry("%s+0+0" % SCREEN_RES)
SysInfo(TK_ROOT)
TK_ROOT.mainloop()
main()