Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 670369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:15:17+00:00 2026-05-14T00:15:17+00:00

I’m not being able to make this line work with Tk import os while(1):

  • 0

I’m not being able to make this line work with Tk

import os
while(1):
    ping = os.popen('ping www.google.com -n 1')
    result = ping.readlines()
    msLine = result[-1].strip()
    print msLine.split(' = ')[-1]

I’m trying to create a label and text = msLine.split… but everything freezes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:15:17+00:00Added an answer on May 14, 2026 at 12:15 am

    Your example code shows no GUI code. It is impossible to guess why your GUI freezes without seeing the code. Though, your code is pretty buggy so even if there were GUI code in your post it likely wouldn’t help.

    Is it possible that you’re forgetting to call the mainloop() method on your root widget? That would explain the freeze. And if you are calling mainloop(), there’s no reason to do while(1) since the main event loop itself is an infinite loop. Why are you calling ping in a loop?

    One specific problem you have is that you are calling ping wrong. For one, the option “-n 1” needs to come before the hostname argument (ie: ‘ping -n 1 http://www.google.com‘ instead of ‘ping http://www.google.com -n 1′). Also, -n is the wrong thing to do. I think you want “-c 1”

    Here’s a working example of how you can ping periodically and update a label:

    import os
    from Tkinter import *
    class App:
        def __init__(self):
            self.root = Tk()
            self.create_ui()
            self.url = "www.google.com"
            self.do_ping = False
            self.root.mainloop()
    
        def create_ui(self):
            self.label = Label(self.root, width=32, text="Ping!")
            self.button = Button(text="Start", width=5, command=self.toggle)
            self.button.pack(side="top")
            self.label.pack(side="top", fill="both", expand=True)
    
        def toggle(self):
            if self.do_ping:
                self.do_ping = False
                self.button.configure(text="Start")
            else:
                self.do_ping = True
                self.button.configure(text="Stop")
                self.ping()
    
        def ping(self):
            if not self.do_ping:
                return
            ping = os.popen('ping -c 1 %s' % self.url)
            result = ping.readlines()
            msLine = result[-1].strip()
            data = msLine.split(' = ')[-1] 
            self.label.configure(text=data)
            # re-schedule to run in another half-second
            if self.do_ping:
                self.root.after(500, self.ping)
    
    app=App()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.