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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:34:18+00:00 2026-05-27T14:34:18+00:00

I came across a pyside script demonstrating a frame, and pyside script demonstrating buttons

  • 0

I came across a pyside script demonstrating a frame, and pyside script demonstrating buttons and box layout.

I made a primitive attempt to combine the two scripts, but I can’t get both of the following functions to work at the same time: run_button_app(True) and run_frame_app(True)

One of the functions uses this statement: app_frame = QApplication([])
and the other uses this statement: app1 = QtGui.QApplication(sys.argv)
The tutorials I used did not include material explaining these things. I’ve ordered a book on Pyside and PyQt programming, but it hasn’t arrived yet.

I’m trying to figure out how to use the frame (e.g., to put a couple of frames in window, and put my buttons in one of the frames), but I haven’t been able to figure that out yet, nor where to get info (example? tutorial?) about how to use the frame.

I am a pyside and python newbie.
Any tips (e.g., links to relevant tutorials) would be much appreciated.

Thanks,
Marc

    """
    Cannibalized by Marc from 
        http://zetcode.com/gui/pysidetutorial/
        ZetCode PySide tutorial  author: Jan Bodnar    website: zetcode.com 
            and    
        # explore QFrame()   #http://www.daniweb.com/software-development/python/threads/366177
    """

    import sys
    from PySide.QtCore import *
    from PySide.QtGui import *
    from PySide import QtGui

    initiate_app = False

    class Example(QtGui.QWidget):

        def __init__(self):
            super(Example, self).__init__()
            # The following 4 lines are from "Window_with_frame.py"
            # setGeometry(x_pos, y_pos, width, height)
            # self.setGeometry(100, 150, width, height)
            # self.setWindowTitle(title)
            # self.make_frame()

            self.initUI()

        def initUI(self):

            okButton = QtGui.QPushButton("OKh1_1")
            cancelButton = QtGui.QPushButton("Cancel1_2")
            ThirdButton = QtGui.QPushButton("Third1_3")
            hbox2_1Button = QtGui.QPushButton("hbox2_Btn1")
            hbox2_2Button = QtGui.QPushButton("hbox2_Btn2")
            hbox3_1Button = QtGui.QPushButton("hbox3_Btn1")
            hbox3_2Button = QtGui.QPushButton("hbox3_Btn2")
            Vbox1Button = QtGui.QPushButton("Vbox1Button")
            Vbox2Button = QtGui.QPushButton("Vbox2Button")
            NewQqPtA1Button = QtGui.QPushButton("NewQqPtA1")
            NewQqPtB2Button = QtGui.QPushButton("NewQqPtB2")

            hbox1 = QtGui.QHBoxLayout()
            hbox1.addStretch(1)
            hbox1.addWidget(okButton)
            hbox1.addWidget(cancelButton)
            hbox1.addWidget(ThirdButton)

            hbox2 = QtGui.QHBoxLayout()
            hbox2.addStretch(1)
            hbox2.addWidget(hbox2_1Button)
            hbox2.addWidget(hbox2_2Button)
            hbox1.addLayout(hbox2)

            hbox3 = QtGui.QHBoxLayout()
            hbox3.addStretch(1)        
            hbox3.addWidget(hbox3_1Button)
            hbox3.addWidget(hbox3_2Button)

            vbox1 = QtGui.QVBoxLayout()
            vbox1.addStretch(1)
            vbox1.addWidget(Vbox1Button)
            vbox1.addLayout(hbox1)
            #vbox1.addLayout(hbox2)
            vbox1.addLayout(hbox3)

            vbox2 = QtGui.QVBoxLayout()
            vbox2.addStretch(1)
            vbox2.addWidget(Vbox2Button)
            vbox2.addLayout(vbox1)

            self.setLayout(vbox2)    

            self.setGeometry(300, 300, 300, 150)
            self.setWindowTitle('Buttons')
            #self.make_frame()
            self.show()

    # The class is from "Window_with_frame.py"

    class FrameTester(QWidget):
        def __init__(self, title, width, height, parent=None):
            # create the window (this will be instance self)
            QWidget.__init__(self, parent)
            # setGeometry(x_pos, y_pos, width, height)
            self.setGeometry(100, 150, width, height)
            self.setWindowTitle(title)
            self.make_frame()

        def make_frame(self):
            frame = QFrame(self)
            frame.setLineWidth(3)
            frame.setFrameStyle(QFrame.Box|QFrame.Sunken)        
            # this will not have the effect you hope for
            #frame.setFrameRect(QRect(10, 10, 20, 20))       
            layout = QBoxLayout(QBoxLayout.LeftToRight)
            layout.addWidget(frame)        
            self.setLayout(layout)



    def run_frame_app(initiate_app = False):        
        # create the Qt Application
        if initiate_app == True:        
            app_frame = QApplication([])        
            title = "Window"
            width = 800
            height = 600
            tester = FrameTester(title, width, height)
            tester.show()        
            # run the main Qt event loop
            app_frame.exec_()


    def run_button_app(initiate_app = False):   
        # create the Qt Application
        if initiate_app == True:        
            app1 = QtGui.QApplication(sys.argv)
            ex = Example()
            run_frame_app()
            sys.exit(app1.exec_())    



    if __name__ == '__main__':
        #run_button_app(True)
        run_frame_app(True)
  • 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-27T14:34:19+00:00Added an answer on May 27, 2026 at 2:34 pm

    You can’t run two QAplication instances at once,
    here some information in this tutorial.

    I dont fully understand what are you trying to do, but if you want to add Example widget (with buttons) to FrameTester, you need to create some layout in FrameTester and add Example instance to this layout (there are many tutorials on it).

    If you want Example widget to have frame, you need to subclass QFrame:

    class Example(QFrame):
        def __init__(self, parent=None):
            super(Example, self).__init__(parent)
            self.setLineWidth(3)
            self.setFrameStyle(QFrame.Box|QFrame.Sunken)  
    # ...    
    

    Tip for the future, when you defining some Widget, provide parent argument to __init__ function, so it can be used in other places.

    To learn more try zetcode tutorial, PySide documentation

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

Sidebar

Related Questions

Came across a line in OpenSSL that made me do a double take... if
I came across two threads: Socket with recv-timeout: What is wrong with this code?
Came across this, what is -z in the shell script if [ -z ${FILE_LIST}
I came across a difference in speed using the following two structs: public struct
Came across something strange while migrating to my new server. I have a script
Came across this curiosity recently. One solution, with two projects within it (ORM and
i came across following shell script as part of makefile in u-boot. what it
Came across this error today. Wondering if anyone can tell me what it means:
Came across something like this today, and was wondering if there was an equivalent
I came across this article written by Andrei Alexandrescu and Petru Marginean many years

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.