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 7887247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:31:45+00:00 2026-06-03T05:31:45+00:00

I’m trying to make an infinite loop (with a break) that runs alongside my

  • 0

I’m trying to make an infinite loop (with a break) that runs alongside my Tkinter window and interacts with widgets on it. Yes, I have done my research, but when I run my code and activate the function the window stops responding.

I’ve deleted the ‘while true’ from the method, and at the end of it placed:

if self.connected:
    root.after(100, self.listenServer(id, req))

I think the problem is that the function takes a little while to complete (I’m making an Omegle client, so it has to connect to the server). I can tell that it runs six times, because I put a print statement in the method.

Is there a simple (AKA no threading) method to solve this problem?

Well, if threading is the only way to do it, then I guess it would be fine

Here are my connect and listen methods:

    def listenServer(self, id, req):
    site = url.urlopen(req)

    #We read the HTTP output to get what's going on
    rec = site.read()

    if 'waiting' in rec:
        self.chatbox.config(state=NORMAL)
        self.chatbox.insert(END, "Waiting...\n", "italic")
        self.chatbox.config(state=DISABLED)

    elif 'connected' in rec:
        self.chatbox.config(state=NORMAL)
        self.chatbox.insert(END, "Stranger connected\n", "italic")
        self.chatbox.config(state=DISABLED)

    elif 'strangerDisconnected' in rec:
        self.chatbox.config(state=NORMAL)
        self.chatbox.insert(END, "Stranger Disconnected\n", "italic")
        self.chatbox.config(state=DISABLED)
        self.connected = False

    elif 'typing' in rec:
        self.chatbox.config(state=NORMAL)
        self.chatbox.insert(END, "Stranger is typing\n", "italic")
        self.chatbox.config(state=DISABLED)

    elif 'gotMessage' in rec:
        self.chatbox.config(state=NORMAL)
        self.chatbox.insert(END, "Stranger: " + rec[17:len(rec) - 3] + "\n")
        self.chatbox.config(state=DISABLED)

def OmegleConnect(self):
    self.chatbox.config(state=NORMAL)
    self.chatbox.insert(END, "Connecting...\n", "italic")
    self.chatbox.config(state=DISABLED)

    site = url.urlopen('http://omegle.com/start', '')
    id = site.read()
    id = id[1:len(id) - 1]
    self.chatbox.config(state=NORMAL)
    self.chatbox.insert(END, "Stranger ID: " + id + "\n", "title")
    self.chatbox.config(state=DISABLED)
    req = url.Request('http://omegle.com/events', urllib.urlencode({'id':id}))
    self.chatbox.config(state=NORMAL)
    self.chatbox.insert(END, "Finding a stranger...\n", "italic")
    self.chatbox.config(state=DISABLED)
    self.connected = True
    root.after(100, self.listenServer(id, req))

Yes, I know this is quite inefficient with the way it writes to the text widget. I tried making a method to do it more easily, but it wasn’t working. I’ll worry about that once I get this up and running.

  • 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-06-03T05:31:47+00:00Added an answer on June 3, 2026 at 5:31 am

    The issue here is that the window needs to be continuously updating in order for the window to react to input – that’s a reality of the way the program works, and makes sense.

    On the other hand, you want to do something in a loop which doesn’t allow the window to update – given this, there is no way for the window to react.

    So no, there is no solution to this that won’t involve threading or multiprocessing in some way – you need to do two things at once.

    Possible solutions:

    If you don’t want to deal with threading directly, you could use a library like twisted to provide the networking you are talking about, which will avoid you waiting on your request to complete.

    The other main option is to use the multiprocessing module or threading module to move the things you want to do simultaneously to updating your interface into a new thread/process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.