Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b83c1d9

Browse files
committed
PyQt5 Widgets
1 parent afd9fba commit b83c1d9

File tree

13 files changed

+401
-0
lines changed

13 files changed

+401
-0
lines changed

‎pyqt5/tutorials/basic-widgets/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# PyQt5 Widgets
2+
3+
This folder contains the code examples for the PythonGUIs tutorial [PyQt5 Widgets](https://www.pythonguis.com/tutorials/pyqt-basic-widgets/).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtWidgets import (
5+
QApplication,
6+
QCheckBox,
7+
QComboBox,
8+
QDial,
9+
QDoubleSpinBox,
10+
QLabel,
11+
QLineEdit,
12+
QListWidget,
13+
QMainWindow,
14+
QSlider,
15+
QSpinBox,
16+
)
17+
18+
19+
class MainWindow(QMainWindow):
20+
21+
def __init__(self):
22+
super(MainWindow, self).__init__()
23+
self.setWindowTitle("My App")
24+
25+
26+
app = QApplication(sys.argv)
27+
w = MainWindow()
28+
w.show()
29+
app.exec()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtWidgets import QApplication, QCheckBox, QMainWindow
5+
6+
7+
class MainWindow(QMainWindow):
8+
def __init__(self):
9+
super(MainWindow, self).__init__()
10+
11+
self.setWindowTitle("My App")
12+
13+
widget = QCheckBox()
14+
widget.setCheckState(Qt.Checked)
15+
16+
widget.stateChanged.connect(self.show_state)
17+
18+
self.setCentralWidget(widget)
19+
20+
def show_state(self, s):
21+
print(s == Qt.Checked)
22+
print(s)
23+
24+
25+
app = QApplication(sys.argv)
26+
w = MainWindow()
27+
w.show()
28+
app.exec()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QComboBox, QMainWindow
4+
5+
6+
class MainWindow(QMainWindow):
7+
def __init__(self):
8+
super(MainWindow, self).__init__()
9+
10+
self.setWindowTitle("My App")
11+
12+
widget = QComboBox()
13+
widget.addItems(["One", "Two", "Three"])
14+
15+
widget.currentIndexChanged.connect(self.index_changed)
16+
17+
widget.currentTextChanged.connect(self.text_changed)
18+
19+
self.setCentralWidget(widget)
20+
21+
def index_changed(self, i):
22+
print(i)
23+
24+
def text_changed(self, s):
25+
print(s)
26+
27+
28+
app = QApplication(sys.argv)
29+
w = MainWindow()
30+
w.show()
31+
app.exec()

‎pyqt5/tutorials/basic-widgets/dial.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QDial, QMainWindow
4+
5+
6+
class MainWindow(QMainWindow):
7+
def __init__(self):
8+
super().__init__()
9+
10+
self.setWindowTitle("My App")
11+
12+
widget = QDial()
13+
widget.setRange(-10, 100)
14+
widget.setSingleStep(1)
15+
16+
widget.valueChanged.connect(self.value_changed)
17+
widget.sliderMoved.connect(self.slider_position)
18+
widget.sliderPressed.connect(self.slider_pressed)
19+
widget.sliderReleased.connect(self.slider_released)
20+
21+
self.setCentralWidget(widget)
22+
23+
def value_changed(self, i):
24+
print(i)
25+
26+
def slider_position(self, p):
27+
print("Position", p)
28+
29+
def slider_pressed(self):
30+
print("Pressed!")
31+
32+
def slider_released(self):
33+
print("Released")
34+
35+
36+
app = QApplication(sys.argv)
37+
w = MainWindow()
38+
w.show()
39+
app.exec()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtGui import QPixmap
5+
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow
6+
7+
8+
class MainWindow(QMainWindow):
9+
10+
def __init__(self):
11+
super(MainWindow, self).__init__()
12+
13+
self.setWindowTitle("My App")
14+
15+
widget = QLabel()
16+
widget.setPixmap(QPixmap("otje.jpg"))
17+
widget.setScaledContents(True)
18+
widget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
19+
20+
self.setCentralWidget(widget)
21+
22+
23+
app = QApplication(sys.argv)
24+
w = MainWindow()
25+
w.show()
26+
app.exec()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow
5+
6+
7+
class MainWindow(QMainWindow):
8+
9+
def __init__(self):
10+
super(MainWindow, self).__init__()
11+
12+
self.setWindowTitle("My App")
13+
14+
widget = QLabel("Hello")
15+
font = widget.font()
16+
font.setPointSize(30)
17+
widget.setFont(font)
18+
widget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
19+
20+
self.setCentralWidget(widget)
21+
22+
23+
app = QApplication(sys.argv)
24+
w = MainWindow()
25+
w.show()
26+
app.exec()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QLineEdit, QMainWindow
4+
5+
6+
class MainWindow(QMainWindow):
7+
8+
def __init__(self):
9+
super(MainWindow, self).__init__()
10+
11+
self.setWindowTitle("My App")
12+
13+
widget = QLineEdit()
14+
widget.setMaxLength(10)
15+
widget.setPlaceholderText("Enter your text")
16+
17+
# widget.setReadOnly(True) # uncomment this to make readonly
18+
19+
widget.returnPressed.connect(self.return_pressed)
20+
widget.selectionChanged.connect(self.selection_changed)
21+
widget.textChanged.connect(self.text_changed)
22+
widget.textEdited.connect(self.text_edited)
23+
24+
self.setCentralWidget(widget)
25+
26+
def return_pressed(self):
27+
print("Return pressed!")
28+
self.centralWidget().setText("BOOM!")
29+
30+
def selection_changed(self):
31+
print("Selection changed")
32+
print(self.centralWidget().selectedText())
33+
34+
def text_changed(self, s):
35+
print("Text changed...")
36+
print(s)
37+
38+
def text_edited(self, s):
39+
print("Text edited...")
40+
print(s)
41+
42+
43+
app = QApplication(sys.argv)
44+
w = MainWindow()
45+
w.show()
46+
app.exec()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QListWidget, QMainWindow
4+
5+
6+
class MainWindow(QMainWindow):
7+
def __init__(self):
8+
super(MainWindow, self).__init__()
9+
10+
self.setWindowTitle("My App")
11+
12+
widget = QListWidget()
13+
widget.addItems(["One", "Two", "Three"])
14+
15+
widget.currentItemChanged.connect(self.index_changed)
16+
widget.currentTextChanged.connect(self.text_changed)
17+
18+
self.setCentralWidget(widget)
19+
20+
def index_changed(self, i):
21+
print(i.text())
22+
23+
def text_changed(self, s):
24+
print(s)
25+
26+
27+
app = QApplication(sys.argv)
28+
w = MainWindow()
29+
w.show()
30+
app.exec()

‎pyqt5/tutorials/basic-widgets/otje.jpg

129 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /