---
# System prepended metadata

title: '<center><i class="fa fa-edit"></i> Smart Dispenser: Understanding PyQt </center>'
tags: [Internship]

---

# <center><i class="fa fa-edit"></i> Smart Dispenser: Understanding PyQt </center>
###### tags: `Internship`
:::info
**Goal:**
- [x] Understanding PyQt Structure

**Resources:**
[PyQt](https://hackmd.io/Ibk_VuuWRXOjkION4wk3tg)
[目前做到現在的程式](https://drive.google.com/drive/folders/1QNJJxxug1Njb9ATe-BdzcZKZZ1PGI2Sd?usp=sharing)
:::

### PyQt QLabel
```
from PyQt6.QtWidgets import *
app = QApplication([])
label = QLabel('Hello World!')
label.show()
app.exec()
```
### PyQt Box Layout
```
from PyQt6.QtWidgets import *
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
layout.addWidget(QPushButton('Top'))
layout.addWidget(QPushButton('Bottom'))
window.setLayout(layout)
window.show()
app.exec()
```

### PyQt Signals and Slots
```
from PyQt6.QtWidgets import *

app = QApplication([])
button = QPushButton('Click')

def on_button_clicked():
    alert = QMessageBox()
    alert.setText('You clicked the button!')
    alert.exec()

button.clicked.connect(on_button_clicked)
button.show()
app.exec()
```
### PyQt Designer Python
```
from PyQt6 import uic
from PyQt6.QtWidgets import QApplication

Form, Window = uic.loadUiType("dialog.ui")

app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.show()
app.exec()
```