Skip to content

Commit d2cc793

Browse files
committed
PyQT Tutorial 2
Creación de GUI usando Layouts
1 parent 5683d36 commit d2cc793

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

02-layout/absolute.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit
4+
5+
6+
if __name__ == '__main__':
7+
app = QApplication(sys.argv)
8+
9+
w = QWidget()
10+
w.setWindowTitle('Layout PyQT-5')
11+
w.resize(250, 120)
12+
13+
lblName = QLabel("Nombre:", w)
14+
lblName.move(20, 20)
15+
16+
lblPass = QLabel("Contraseña:", w)
17+
lblPass.move(20, 50)
18+
19+
txtName = QLineEdit(w)
20+
txtName.setPlaceholderText("Nombre de usuario")
21+
txtName.move(100, 15)
22+
23+
txtPass = QLineEdit(w)
24+
txtPass.setPlaceholderText("Contraseña de usuario")
25+
txtPass.move(100, 45)
26+
27+
btnLogin = QPushButton("Login", w)
28+
btnLogin.move(20, 80)
29+
btnLogin.resize(218, 30)
30+
31+
w.show()
32+
33+
sys.exit(app.exec_())

02-layout/box-layout.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout
3+
4+
5+
if __name__ == '__main__':
6+
app = QApplication(sys.argv)
7+
8+
w = QWidget()
9+
w.setWindowTitle('Layout PyQT-5')
10+
w.resize(250, 120)
11+
12+
vbox = QVBoxLayout()
13+
vbox.setSpacing(20)
14+
15+
for n in range(5):
16+
if n == 2:
17+
hbox = QHBoxLayout()
18+
for m in range(3):
19+
hbox.addWidget(QPushButton("Button #" + str(m)))
20+
vbox.addLayout(hbox)
21+
else:
22+
vbox.addWidget(QPushButton("Button #" + str(n)))
23+
24+
w.setLayout(vbox)
25+
w.show()
26+
27+
sys.exit(app.exec_())

02-layout/grid-layout.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QGridLayout
4+
5+
6+
if __name__ == '__main__':
7+
app = QApplication(sys.argv)
8+
9+
w = QWidget()
10+
w.setWindowTitle('Layout PyQT-5')
11+
w.resize(250, 120)
12+
13+
lblName = QLabel("Nombre:")
14+
txtName = QLineEdit()
15+
txtName.setPlaceholderText("Nombre de usuario")
16+
17+
lblPass = QLabel("Contraseña:")
18+
txtPass = QLineEdit(w)
19+
txtPass.setPlaceholderText("Contraseña de usuario")
20+
21+
grid = QGridLayout()
22+
grid.addWidget(lblName, 0, 0)
23+
grid.addWidget(txtName, 0, 1)
24+
grid.addWidget(lblPass, 1, 0)
25+
grid.addWidget(txtPass, 1, 1)
26+
27+
btnLogin = QPushButton("Login", w)
28+
grid.addWidget(btnLogin, 2, 0, 1, 2)
29+
30+
w.setLayout(grid)
31+
w.show()
32+
33+
sys.exit(app.exec_())

0 commit comments

Comments
 (0)