简体   繁体   English

执行 ping 命令后退出按钮不起作用,但在执行此操作之前(tkinter)

[英]Exit button doesnt work after executeing ping command but does before doing so (tkinter)

So im very new to python and I'm basically trying to make a program were the user inputs a targets IP and then presses a button below to Execute the command (start the pinging process) and this I've done successfully but now I wanted to add an exit button below to stop the pinging process but I've got a problem.所以我对 python 非常陌生,我基本上是在尝试制作一个程序,如果用户输入一个目标 IP 然后按下下面的一个按钮来执行命令(开始 ping 过程),我已经成功完成了,但现在我想要在下方添加退出按钮以停止 ping 过程,但我遇到了问题。 The button works fine before you press execute (works as intended it closes the application window) but when the script is running the button doesn't work at all and just kinda crashes the window but keeps the command running.该按钮在您按下执行之前工作正常(按预期工作,它会关闭应用程序窗口)但是当脚本运行时,该按钮根本不起作用,只是有点使 window 崩溃但保持命令运行。 How can I make the button work att all times (make it work when the script is running).如何使按钮始终工作(使其在脚本运行时工作)。

import tkinter as tk #import tkinter and tkinter library
from tkinter import ttk #package to style widget
import subprocess

def window(): #runs the window ??? i think
    #address = input("Enter Ip Here:")
    subprocess.call(f"ping {text.get()} -t -l 65500")

# root window
root = tk.Tk() # root?
root.geometry('200x200')   #window size
root.resizable(False, False) # makes window non rezisable
root.title('Ping Of Death') #window title

var = tk.StringVar #variable tkinter = StringVar

text = tk.Entry(root,textvariable=var, width = 25)
text.pack()


# execute button
execute_button = ttk.Button( #defines the execute button
    root,
    text='Execute', #defines the text on the button
    command=window
)

execute_button.pack( #package for button
    ipadx=5, #x size
    ipady=5, #y size
    expand=True # ???
)




exit_button = ttk.Button(
    root, text="Exit" ,
    command=root.quit
    )

exit_button.pack(pady=20)




root.mainloop() #to keep everything in a loop

I'm pretty sure that subprocess.call is blocking, so search on "subprocess.call non-blocking" and asyncio as an alternative.我很确定 subprocess.call 是阻塞的,所以搜索“subprocess.call non-blocking”和 asyncio 作为替代。

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

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