效果预览
main_window.ui
<?xml version="1.0" encoding="UTF-8"?>
< ui version = " 4.0" >
< class> MainWindow</ class>
< widget class = " QMainWindow" name = " MainWindow" >
< property name = " geometry" >
< rect>
< x> 0</ x>
< y> 0</ y>
< width> 524</ width>
< height> 353</ height>
</ rect>
</ property>
< property name = " windowTitle" >
< string> MainWindow</ string>
</ property>
< widget class = " QWidget" name = " centralwidget" >
< layout class = " QVBoxLayout" name = " verticalLayout" >
< item>
< layout class = " QHBoxLayout" name = " horizontalLayout" >
< item>
< widget class = " QPushButton" name = " pushButton" >
< property name = " text" >
< string> PushButton</ string>
</ property>
</ widget>
</ item>
< item>
< widget class = " QPushButton" name = " pushButton_2" >
< property name = " text" >
< string> PushButton</ string>
</ property>
</ widget>
</ item>
< item>
< widget class = " QPushButton" name = " pushButton_3" >
< property name = " text" >
< string> PushButton</ string>
</ property>
</ widget>
</ item>
</ layout>
</ item>
< item>
< layout class = " QHBoxLayout" name = " horizontalLayout_2" >
< item>
< widget class = " QLineEdit" name = " lineEdit" />
</ item>
< item>
< widget class = " QCheckBox" name = " checkBox" >
< property name = " text" >
< string> CheckBox</ string>
</ property>
</ widget>
</ item>
</ layout>
</ item>
</ layout>
</ widget>
< widget class = " QMenuBar" name = " menubar" >
< property name = " geometry" >
< rect>
< x> 0</ x>
< y> 0</ y>
< width> 524</ width>
< height> 22</ height>
</ rect>
</ property>
</ widget>
< widget class = " QStatusBar" name = " statusbar" />
</ widget>
< resources/>
< connections/>
</ ui>
main_window.py
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_MainWindow ( object ) :
def setupUi ( self, MainWindow) :
MainWindow. setObjectName( "MainWindow" )
MainWindow. resize( 524 , 353 )
self. centralwidget = QtWidgets. QWidget( parent= MainWindow)
self. centralwidget. setObjectName( "centralwidget" )
self. verticalLayout = QtWidgets. QVBoxLayout( self. centralwidget)
self. verticalLayout. setObjectName( "verticalLayout" )
self. horizontalLayout = QtWidgets. QHBoxLayout( )
self. horizontalLayout. setObjectName( "horizontalLayout" )
self. pushButton = QtWidgets. QPushButton( parent= self. centralwidget)
self. pushButton. setObjectName( "pushButton" )
self. horizontalLayout. addWidget( self. pushButton)
self. pushButton_2 = QtWidgets. QPushButton( parent= self. centralwidget)
self. pushButton_2. setObjectName( "pushButton_2" )
self. horizontalLayout. addWidget( self. pushButton_2)
self. pushButton_3 = QtWidgets. QPushButton( parent= self. centralwidget)
self. pushButton_3. setObjectName( "pushButton_3" )
self. horizontalLayout. addWidget( self. pushButton_3)
self. verticalLayout. addLayout( self. horizontalLayout)
self. horizontalLayout_2 = QtWidgets. QHBoxLayout( )
self. horizontalLayout_2. setObjectName( "horizontalLayout_2" )
self. lineEdit = QtWidgets. QLineEdit( parent= self. centralwidget)
self. lineEdit. setObjectName( "lineEdit" )
self. horizontalLayout_2. addWidget( self. lineEdit)
self. checkBox = QtWidgets. QCheckBox( parent= self. centralwidget)
self. checkBox. setObjectName( "checkBox" )
self. horizontalLayout_2. addWidget( self. checkBox)
self. verticalLayout. addLayout( self. horizontalLayout_2)
MainWindow. setCentralWidget( self. centralwidget)
self. menubar = QtWidgets. QMenuBar( parent= MainWindow)
self. menubar. setGeometry( QtCore. QRect( 0 , 0 , 524 , 22 ) )
self. menubar. setObjectName( "menubar" )
MainWindow. setMenuBar( self. menubar)
self. statusbar = QtWidgets. QStatusBar( parent= MainWindow)
self. statusbar. setObjectName( "statusbar" )
MainWindow. setStatusBar( self. statusbar)
self. retranslateUi( MainWindow)
QtCore. QMetaObject. connectSlotsByName( MainWindow)
def retranslateUi ( self, MainWindow) :
_translate = QtCore. QCoreApplication. translate
MainWindow. setWindowTitle( _translate( "MainWindow" , "MainWindow" ) )
self. pushButton. setText( _translate( "MainWindow" , "PushButton" ) )
self. pushButton_2. setText( _translate( "MainWindow" , "PushButton" ) )
self. pushButton_3. setText( _translate( "MainWindow" , "PushButton" ) )
self. checkBox. setText( _translate( "MainWindow" , "CheckBox" ) )
main.py
import main_window
import sys
from PyQt6. QtWidgets import QApplication, QMainWindow
if __name__ == '__main__' :
app = QApplication( sys. argv)
window = QMainWindow( )
ui = main_window. Ui_MainWindow( )
ui. setupUi( window)
window. show( )
sys. exit( app. exec ( ) )