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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:28:02+00:00 2026-05-26T19:28:02+00:00

python 3.2.2 gtk3 3.2.2 python-gobject 3.0.2 I’m trying to display a GUI and do

  • 0
  • python 3.2.2
  • gtk3 3.2.2
  • python-gobject 3.0.2

I’m trying to display a GUI and do some work in the background. As I understand it should look something like this:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import time
from threading import Thread
from gi.repository import Gtk, Gdk

class Gui():
        def run(self):
                self.Window = Gtk.Window()
                self.Window.set_border_width(8)
                self.Window.set_title("Некий GUI")
                self.Window.connect('destroy', lambda x: self.stop())

                self.outBut = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
                self.outBut.set_size_request(150, 35)
                self.outBut.connect('clicked', lambda x: self.passfun)
                self.Window.add(self.outBut)

                self.Window.show_all()

        def stop(self):
                Gtk.main_quit()

        def passfun(self):
                pass

class LoopSleep(Thread):
        def run(self):
                i = 1
                while True:
                        print(i)
                        i = i + 1
                        #time.sleep(1)



gui = Gui()
gui.run()

loopSleep = LoopSleep()
loopSleep.start()

Gdk.threads_init()
Gdk.threads_enter()
Gtk.main()
Gdk.threads_leave()

But it does not work. Several cycles occurs when you press the button. And the cycle runs after the window is closed. But not together.

What I do wrong?

  • 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-26T19:28:03+00:00Added an answer on May 26, 2026 at 7:28 pm

    Can’t claim to be any expert on python threading nor gtk3 but after playing around a little with your example I found something that appears to work the way you want it. Instead of sub classing Thread i use threading.start(target=loop_sleep), and placed that inside Gui.

    Glib.threads_init() also seem to be needed.

    #!/usr/bin/env python3
    from gi.repository import Gtk,Gdk, GLib
    import threading 
    import time
    
    class Gui(Gtk.Window):
      def __init__(self):
          self.Window = Gtk.Window()
          self.Window.set_border_width(8)
          self.Window.set_title("Некий GUI")
          self.Window.connect('destroy', lambda x: self.stop())
    
          self.outBut = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
          self.outBut.set_size_request(150, 35)
          self.Window.connect('destroy', lambda x: self.stop())
          self.Window.add(self.outBut)
    
          self.Window.show_all()
          threading.Thread(target=loop_sleep).start()
    
      def stop(self):
          Gtk.main_quit()
    
      def passfun(self):
          pass
    
    def loop_sleep():
          i = 1
          while True:
               print(i)
               i = i + 1
               #time.sleep(1)
    
    
    
    app = Gui()
    GLib.threads_init()
    Gdk.threads_init()
    Gdk.threads_enter()
    Gtk.main()
    Gdk.threads_leave()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python newb...beware! I am trying to recursively ftp some files. In the script below,
Python's convention is that variables are created by first assignment, and trying to read
Python has the idea of metaclasses that, if I understand correctly, allow you to
I'm using python and want to embed gtk3 widgets in clutter stage. However, it
Python and django newbie question, here is code: class Client(User) #some fields client=Client() client.save()
Python is installed in a local directory. My directory tree looks like this: (local
Python newbie here. I'm trying to create a black jack game in which the
Python's inner/nested classes confuse me. Is there something that can't be accomplished without them?
Python newbie here. I'm trying to package a console app following this doc .
Python version: 2.6.6 PySerial version: 2.5 Arduino board: Duemilanove 328 I have written some

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.