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

  • Home
  • SEARCH
  • 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 712009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:48:00+00:00 2026-05-14T04:48:00+00:00

Can someone give me a simple example involving threads in this manner, please. Problem

  • 0

Can someone give me a simple example involving threads in this manner, please.

Problem with my code is that when I click button One, GUI freezes until its finished. I want buttons to stay responsive when def is being executed. How can i fix that?

class fun:
        wTree = None
        def __init__( self ):                
                self.wTree = gtk.glade.XML( "ui.glade" )

                dic = {
                        "on_buttonOne" : self.one,
                        "on_buttonTwo" : self.two,
                }
                self.wTree.signal_autoconnect( dic )              
                gtk.main()

        def sone(self, widget):
           time.sleep(1)
           print "1"
           time.sleep(1)
           print "2"
           time.sleep(1)
           print "3"
        def stwo(self, widget):
           time.sleep(1)
           print "4"
           time.sleep(1)
           print "5"
           time.sleep(1)
           print "6"
do=fun()

Pretty please, help me.

  • 1 1 Answer
  • 1 View
  • 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-14T04:48:01+00:00Added an answer on May 14, 2026 at 4:48 am

    When using gtk, it will run a main loop, and you schedule everything you want to do as events to the gtk loop. You don’t need threads to do anything.

    Here’s a complete, full, ready-to-run example that uses glib.timeout_add to do what you want.

    Note that clicking on both buttons (or multiple times on a button) doesn’t freeze the gui and everything happens “at the same time”…

    import gtk
    import glib
    
    def yieldsleep(func):
        def start(*args, **kwds):
            iterable = func(*args, **kwds)
            def step(*args, **kwds):
                try:
                    time = next(iterable)
                    glib.timeout_add_seconds(time, step)
                except StopIteration:
                    pass
            glib.idle_add(step)
        return start
    
    class Fun(object):
        def __init__(self):
            window = gtk.Window()
    
            vbox = gtk.VBox()
    
            btnone = gtk.Button('one')
            btnone.connect('clicked', self.click_one)
            btnone.show()
            vbox.pack_start(btnone)
    
            btntwo = gtk.Button('two')
            btntwo.connect('clicked', self.click_two)
            btntwo.show()
            vbox.pack_start(btntwo)
    
            vbox.show()
            window.add(vbox)
            window.show()
    
        @yieldsleep
        def click_one(self, widget, data=None):
            yield 1 #time.sleep(1)
            print '1'
            yield 1 #time.sleep(1)
            print '2'
            yield 1 #time.sleep(1)
            print '3'
    
        @yieldsleep
        def click_two(self, widget, data=None):
            yield 1 #time.sleep(1)
            print '4'
            yield 1 #time.sleep(1)
            print '5'
            yield 1 #time.sleep(1)
            print '6'
    
    do = Fun()
    gtk.main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone give me some example code that creates a surface with a transparent
This really, really urks me, so I hope that someone can give me a
Can someone give me a simple example of a AnnotatedTimeLine visualization? All the examples
Can someone please explain what the partition by keyword does and give a simple
Can someone give me a very simple example of how one would, say, write
Can someone give an example of a good time to actually use unsafe and
Title is the entire question. Can someone give me a reason why this happens?
When is it appropriate to use CoTaskMemAlloc? Can someone give an example?
I'm sorry, but this keyword doesn't mean anything to me... Can someone give me
How do I use GDI+ with C++Builder ? Can someone give me a simple

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.