I'm trying to configure a label's text to say "Connecting..." when a button is pressed, ping a website, then change the label to say "connection successful.
Here's the code I've been trying (it is all within the init of a class):
#Connect button
def connect_command():
self.subHeading.configure(text="Connecting...")
response = subprocess.run(["ping","google.com"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
if response.returncode == 0:
self.subHeading.configure(text="Connection to google.com successful")
else:
self.subHeading.configure(text="Connection to google.com unsuccessful")
self.connectButton = tk.Button(text="Connect", font=("calibri","15"), command = connect_command)
self.connectButton.pack()
self.subHeading = tk.Label()
self.subHeading.pack()
However when this is run, the label doesn't change until after the site has been pinged, not showing "connecting..." at all, going straight to the "connection successful".
Any ideas on why it's not changing the label?