简体   繁体   English

如何通过单击 Ubuntu 的按钮重新启动 TeamViewer?

[英]How can I restart TeamViewer with a button click on Ubuntu?

I'm developing a GUI and I need for the GUI to be able to restart Teamviewer if it crashes.我正在开发一个 GUI,如果它崩溃,我需要 GUI 能够重新启动 Teamviewer。

I tried doing this using the kernel commands on a Team Viewer "Cheat Sheet"我尝试使用团队查看器“备忘单”上的 kernel 命令执行此操作

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.虽然这声称有效,但据我所知,它实际上并没有重新启动 TeamViewer。

First: your button has command=None so it never run any function so it can't reastart it.首先:你的按钮有command=None所以它永远不会运行任何 function 所以它不能重新启动它。

Second: you can't use try without except or finally so you could get error if your button will run it.第二:如果没有exceptfinally ,您不能使用try ,因此如果您的按钮将运行它,您可能会出错。

Third: you need time.sleep instead of `sleep()第三:你需要time.sleep而不是 `sleep()


BTW: I would use pkexec instead of sudo to show window for password - it is more secure then running sudo without password.顺便说一句:我会使用pkexec而不是sudo来显示 window 的密码 - 它比在没有密码的情况下运行sudo更安全。

Most deamons has option restart to restart it.大多数守护进程都有restart启动选项来重新启动它。 It can also start deamon when it doesn't run.它也可以在它不运行时启动守护进程。 I don't have teamviewer to check if it also has this option.我没有teamviewer来检查它是否也有这个选项。


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM