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 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

Ask A Question

Stats

  • Questions 489k
  • Answers 489k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From this blog: So the final solution was to use… May 16, 2026 at 9:04 am
  • Editorial Team
    Editorial Team added an answer something like: dt.Rows.Cast<DataRow>.Where(s => !excludeMe.Contains(s["RefID"].ToString())); Haven't tried to yet. May 16, 2026 at 9:04 am
  • Editorial Team
    Editorial Team added an answer If you use the global flag, the match method will… May 16, 2026 at 9:04 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

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
How do I use GDI+ with C++Builder ? Can someone give me a simple
I need to write a little program in C that parses a string. I
I am reading this book ( NLTK ) and it is confusing. Entropy is
As a programming exercise, I just finished writing a Sudoku solver that uses the
I've got a while loop, that runs for many seconds and that's why I
Got a little problem i asked about it before but maybe i didnt ask
I'm completely new to MATLAB and I want to know what my options are

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.