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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:37:57+00:00 2026-06-10T14:37:57+00:00

I have a gui in ui_main.py file (designed in Qt Designer). I load it

  • 0

I have a gui in ui_main.py file (designed in Qt Designer). I load it in my main *.py file in this way:

from PyQt4 import QtGui, QtCore
from ui_main import Ui_MainWindow
class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
...

ui_main.py file:

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(667, 559)

I need to resize my main window during application start. My main problem is that I can’t get access to Main window object.

 self.ui.MainWindow.resize(300,300)
 AttributeError: 'Ui_MainWindow' object has no attribute 'MainWindow'

If I add to ui_main.py file:

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.uiui = MainWindow

I can resize my main window with:

self.ui.uiui.resize(300,300) 

But I know that it’s very bad to edit generated ui file. How can I resize my main window without editing a gui file?

  • 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-10T14:37:58+00:00Added an answer on June 10, 2026 at 2:37 pm

    The ui module created by pyuic (via Qt Designer) is just a simple helper class with a couple of initialization methods.

    Both methods take an instance of the top-level ui class from Qt Designer (usually a QMainWindow), and then add the all the ui elements to that instance. This ensures that everything created in Qt Designer is accessible from the top-level widget.

    So your MyForm subclass passes self (an instance of QMainWindow) to setupUi, which then becomes the MainWindow variable you see in your ui file.

    This means you can resize your main window by simply doing:

    self.resize(300, 300)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this GUI screen shots from the design team which i needs to
I have this code to create a database: from sqlalchemy import create_engine from sqlalchemy
I have a GUI application whose main part is a QPlainTextEdit . It is
I have a GUI app written in C++/CLI which has a load of configurable
I have a GUI program, which would call a cmd in this GUI program.
I have a GUI program with one Exit button. When clicking this button, it
I have a main GUI application, that does all of it's actual work in
I have a python gui in qt. the gui is buit using designer. It
I want to download a file from the internet. And so far I have
I have a poker game where I designed a nice pretty GUI that displays

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.