Use tkinter to create a small window with two buttons, one btn to close the window, and the other btn to switch and execute the two passed functions. simple small code can be used for your reference.
The code is as follows:
Import time
Import tkinter as tk
Class Window:
Def _ init _ (self, title = 'nms', width = 300, height = 120, staFunc = bool, stoFunc = bool ):
Self. w = width
Self. h = height
Self. stat = True
Self. staFunc = staFunc
Self. stoFunc = stoFunc
Self. staIco = None
Self. stoIco = None
Self. root = tk. Tk (className = title)
Def center (self ):
Ws = self. root. winfo_screenwidth ()
Hs = self. root. winfo_screenheight ()
X = int (ws/2)-(self. w/2 ))
Y = int (hs/2)-(self. h/2 ))
Self. root. geometry ('{}x {}+ {}'. format (self. w, self. h, x, y ))
Def packBtn (self ):
Self. btnSer = tk. Button (self. root, command = self. event, width = 15, height = 3)
Self. btnSer. pack (padx = 20, side = 'left ')
BtnQuit = tk. Button (self. root, text = 'close windows', command = self. root. quit, width = 15, height = 3)
BtnQuit. pack (padx = 20, side = 'right ')
Def event (self ):
Self. btnSer ['state'] = 'disabled'
If self. stat:
If self. stoFunc ():
Self. btnSer ['text'] = 'start service'
Self. stat = False
Self. root. iconbitmap (self. stoIco)
Else:
If self. staFunc ():
Self. btnSer ['text'] = 'stop service'
Self. stat = True
Self. root. iconbitmap (self. staIco)
Self. btnSer ['state'] = 'active'
Def loop (self ):
Self. root. resizable (False, False) # Disable window size modification
Self. packBtn ()
Self. center () # center window
Self. event ()
Self. root. mainloop ()
######################################## ################################
Def sta ():
Print ('Start .')
Return True
Def sto ():
Print ('Stop .')
Return True
If _ name _ = '_ main __':
Import sys, OS
W = Window (staFunc = sta, stoFunc = sto)
W. staIco = OS .path.join(sys.exe c_prefix, 'dlls \ pyc. ico ')
W. stoIco = OS .path.join(sys.exe c_prefix, 'dlls \ py. ico ')
W. loop ()