-1

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.

6
  • sudo should ask you for password but os.system() will not ask you for password if you don't run it in console.
    – furas
    Sep 30, 2019 at 18:04
  • the user doesn't require a password for sudo commands, I tempered with the sudoers file.
    – Ori Levy
    Sep 30, 2019 at 18:08
  • I would rather use gksudo or pkexec to show window for password. It is more secure.
    – furas
    Sep 30, 2019 at 18:18
  • did you run your code in console to see error mesages ? You can't use try without except - so you should get error.
    – furas
    Sep 30, 2019 at 18:20
  • to restart you can use restart instead of stop and start. It will also start if deamon doesn't run.
    – furas
    Sep 30, 2019 at 18:22

1 Answer 1

0

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.