pyqt6加载ui文件

from PyQt6.QtWidgets import QApplication
from PyQt6 import uic
import sys

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ui = uic.loadUi("./u1.ui")
    ui.show()

    sys.exit(app.exec())

  

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="baseSize">
   <size>
    <width>400</width>
    <height>300</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>学python</string>
  </property>
  <widget class="QLabel" name="label">
   <property name="geometry">
    <rect>
     <x>127</x>
     <y>50</y>
     <width>111</width>
     <height>51</height>
    </rect>
   </property>
   <property name="text">
    <string>大爷你好</string>
   </property>
   <property name="textFormat">
    <enum>Qt::TextFormat::PlainText</enum>
   </property>
   <property name="alignment">
    <set>Qt::AlignmentFlag::AlignCenter</set>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

  

posted @ 2025-06-11 19:15  brady-wang  阅读(49)  评论(0)    收藏  举报