import sys
from PyQt5.Qt import *
from PyQt5.uic import loadUi
class Window(QWidget):
def __init__(self):
super().__init__()
self.setup_ui()
def setup_ui(self):
loadUi("untitled.ui", self)
def slot1(self):
self.pushButton.setText("按钮被点击了")
self.pushButton.adjustSize()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
# untitled.ui
<?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="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>150</x>
<y>80</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>slot1()</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>92</y>
</hint>
<hint type="destinationlabel">
<x>249</x>
<y>92</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slot1()</slot>
</slots>
</ui>