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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:45:18+00:00 2026-06-06T00:45:18+00:00

I just started trying to build simple GUIs because I’ve always used command-line script

  • 0

I just started trying to build simple GUIs because I’ve always used command-line script and wanted to explore more. I’m using the latest versions of both PyQt4 and Python 3.

The problem is that given the code below, on clicking the button in the first window, the second won’t show up but I can’t get why. What am I missing? The script is fully functional (except, of course, for the second window part) so it’s just a copy/paste to try it.

import sys
from PyQt4 import QtCore, QtGui

class GreetWindow(QtGui.QMainWindow):
    def __init__(self):
        # main init
        QtGui.QMainWindow.__init__(self)
        self.setWindowTitle('File Checker!')
        self.centralWidget = QtGui.QWidget()
        self.tLabel = QtGui.QLabel('Hello, and welcome! Please, close me!', self.centralWidget)
        self.bClose = QtGui.QPushButton('Close', self.centralWidget)
        # layout
        self.lVBox = QtGui.QVBoxLayout()
        self.lVBox.setSpacing(2)
        self.lVBox.addWidget(self.tLabel)
        self.lVBox.addWidget(self.bClose)
        # signal connections
        self.connect(self.bClose, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('close()'))
        self.connect(self.bClose, QtCore.SIGNAL('clicked()'), self.showSecond)
        # layout combination
        self.centralWidget.setLayout(self.lVBox)
        self.setCentralWidget(self.centralWidget)
    def showSecond():
        self.theSecond = SecondWindow()
        self.theSecond.show()

class SecondWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.setWindowTitle('This is the second!')
        self.centralWidget = QtGui.QLabel('Mission accomplished')
        self.setCentralWidget(self.centralWidget)

def main():
    app = QtGui.QApplication(sys.argv)
    ex = GreetWindow()
    ex.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

Btw, I really appreciate critics on the way this simple script is coded. I’m starting now with GUIs and I’d like to start in the most pythonic way possible. Thanks all!

  • 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-06T00:45:21+00:00Added an answer on June 6, 2026 at 12:45 am

    Make sure to run your application in a console, so you can see the error output:

    TypeError: showSecond() takes no arguments (1 given)
    

    And indeed, there is an error in the declaration of showSecond: no self! Should be like this:

        def showSecond(self):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started learning Sencha Touch. Trying to build a simple news reader app.
I just started programming and learning Jquery, I'm trying to build a simple show/hide
I have just started trying to build my first wp7 app, and I am
I've just started using maven for trying to build a multi module project. Everything
I have just started learning Rails and I'm trying to build a post/like type
I am just getting started with symfony and am trying to build the database
I'm using build 5.06 of the toolkit and I'm just getting started, trying to
I just started using Django and Python and I'm trying to build a photo
I´ve just started learning GWT and I´m trying to implement http://gwt.google.com/samples/Showcase/Showcase.html#!CwFileUpload and but failing
Warning: I just started learning bash recently and trying to do a recursive function

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.