Reputation: 111
I'm developing a GUI and I need for the GUI to be able to restart Teamviewer if it crashes.
I tried doing this using the kernel commands on a Team Viewer "Cheat Sheet"
import tkinter as tk
import os
import time
root = tk.Tk()
root.title(string="TeamViewerRebootButton")
root.geometry("200x200")
def closePop_upCallback():
None
def teamviewerReboot():
rebooting = tk.Toplevel(master=root)
label = tk.Label(master=rebooting, text="Rebooting...", font=("", 15))
label.pack()
try:
os.system("sudo teamviewer daemon stop")
os.system("sudo teamviewer daemon start")
label.configure(text"Rebooting Complete")
sleep(1)
rebooting.destroy()
rebootTeamViewer = tk.Button(master=root, text="Restart TeamViewer", command=None)
rebootTeamViewer.pack()
root.mainloop()
while this claims to work, as far as I can tell its not actually restarting TeamViewer.
Upvotes: -1
Views: 687
Reputation: 142641
First: your button has command=None
so it never run any function so it can't reastart it.
Second: you can't use try
without except
or finally
so you could get error if your button will run it.
Third: you need time.sleep
instead of `sleep()
BTW: I would use pkexec
instead of sudo
to show window for password - it is more secure then running sudo
without password.
Most deamons has option restart
to restart it. It can also start deamon when it doesn't run. I don't have teamviewer
to check if it also has this option.
import tkinter as tk
import os
import time
# --- functions ---
def teamviewer_reboot():
rebooting = tk.Toplevel(root)
label = tk.Label(rebooting, text="Rebooting...")
label.pack()
try:
os.system("pkexec teamviewer daemon stop")
except Exception as ex:
print('ERROR:', ex)
os.system("pkexec teamviewer daemon start")
#os.system("pkexec teamviewer daemon restart")
label.configure(text="Rebooting Complete")
root.update() # update window because mainloop can't do this when sleep stops it.
time.sleep(2)
rebooting.destroy()
# --- main ---
root = tk.Tk()
root.title(string="TeamViewerRebootButton")
root.geometry("200x200")
reboot_teamviewer = tk.Button(root, text="Restart TeamViewer", command=teamviewer_reboot)
reboot_teamviewer.pack()
root.mainloop()
Upvotes: 0