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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:43:08+00:00 2026-05-22T12:43:08+00:00

A PyQT beginner question. I’m wondering how to do something like the following –

  • 0

A PyQT beginner question. I’m wondering how to do something like the following – modify widgets in the main window from outside the main window class. Like so:

class MainWindow(QtGui.QMainWindow):    

    def __init__(self, parent=None):

        super(MainWindow,self).__init__(parent)

        self.ui = Ui_MainWindow()        
        self.ui.setupUi(self)

        self.ui.progressBar.setMaximum(100)
        self.ui.progressBar.setMinimum(0)
        self.ui.progressBar.setValue(0)

        self.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.slotDoStuff)

    def slotDoStuff(self):
        AnotherFunction()


def AnotherFunction():    
    modify progress bar here...

Is there a way to do something like this? I’d like to subclass the event handlers for various main window actions and not have them all in the MainWindow class. Thanks!

  • 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-22T12:43:08+00:00Added an answer on May 22, 2026 at 12:43 pm

    First, there’s a much better way to connect signals to slots on PyQt:

    self.button.clicked.connect(self.method)
    

    You can use lambda functions to pass extra arguments to methods.

    def do_stuff(arg)
         #do stuff with arg
    

    Then you call

    self.button1.clicked.connect(lambda : do_stuff('btn one'))
    self.button2.clicked.connect(lambda : do_stuff('btn two'))
    

    You can pass whatever you want, including your MainWindow instance to be modified

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

Sidebar

Related Questions

Surely this is possible? I have been hunting through PyQt tutorials and documentation but
I'm using PyQt and am running into this issue. If my import statements are:
Is there a similar function PyOnDemandOutputWindow in Pyqt? This function redirect the console output
How do I render glyphs in pyqt using the svggraphicsItem?
I made a prototype of a project with PyQt and made it work there,
How can i create connection groups inside a QListView with PyQt. The group name
I've been having some trouble with a set of dynamically created buttons in PyQT.
What Python-related code (PyGTK, Glade, Tkinter, PyQT, wxPython, Cairo, ...) could you easily use
I would like a seperate class to run all of my tests, and then
I'm having an annoyingly stubborn problem here, and I would appreciate it if anyone

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.