Movatterモバイル変換


[0]ホーム

URL:


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

Commitf9aafd4

Browse files
authored
Merge pull request#42 from pythonguis/examples-from-articles
Examples from articles
2 parentsb74592e +33c6956 commitf9aafd4

File tree

104 files changed

+3040
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+3040
-0
lines changed
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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
importsys
2+
3+
fromPyQt5.QtWidgetsimport (
4+
QApplication,
5+
QCheckBox,
6+
QComboBox,
7+
QDateEdit,
8+
QDateTimeEdit,
9+
QDial,
10+
QDoubleSpinBox,
11+
QFontComboBox,
12+
QLabel,
13+
QLCDNumber,
14+
QLineEdit,
15+
QMainWindow,
16+
QProgressBar,
17+
QPushButton,
18+
QRadioButton,
19+
QSlider,
20+
QSpinBox,
21+
QTimeEdit,
22+
QVBoxLayout,
23+
QWidget,
24+
)
25+
26+
27+
classMainWindow(QMainWindow):
28+
def__init__(self):
29+
super().__init__()
30+
self.setWindowTitle("Widgets App")
31+
32+
layout=QVBoxLayout()
33+
widgets= [
34+
QCheckBox,
35+
QComboBox,
36+
QDateEdit,
37+
QDateTimeEdit,
38+
QDial,
39+
QDoubleSpinBox,
40+
QFontComboBox,
41+
QLCDNumber,
42+
QLabel,
43+
QLineEdit,
44+
QProgressBar,
45+
QPushButton,
46+
QRadioButton,
47+
QSlider,
48+
QSpinBox,
49+
QTimeEdit,
50+
]
51+
52+
forwinwidgets:
53+
layout.addWidget(w())
54+
55+
widget=QWidget()
56+
widget.setLayout(layout)
57+
self.setCentralWidget(widget)
58+
59+
60+
app=QApplication(sys.argv)
61+
window=MainWindow()
62+
window.show()
63+
app.exec()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
importsys
2+
3+
fromPyQt5.QtCoreimportQt
4+
fromPyQt5.QtWidgetsimport (
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+
classMainWindow(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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
importsys
2+
3+
fromPyQt5.QtCoreimportQt
4+
fromPyQt5.QtWidgetsimportQApplication,QLabel,QMainWindow
5+
6+
7+
classMainWindow(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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
importsys
2+
3+
fromPyQt5.QtCoreimportQt
4+
fromPyQt5.QtGuiimportQPixmap
5+
fromPyQt5.QtWidgetsimportQApplication,QLabel,QMainWindow
6+
7+
8+
classMainWindow(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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
importsys
2+
3+
fromPyQt5.QtCoreimportQt
4+
fromPyQt5.QtWidgetsimportQApplication,QCheckBox,QMainWindow
5+
6+
7+
classMainWindow(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+
defshow_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+
importsys
2+
3+
fromPyQt5.QtWidgetsimportQApplication,QComboBox,QMainWindow
4+
5+
6+
classMainWindow(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+
defindex_changed(self,i):
22+
print(i)
23+
24+
deftext_changed(self,s):
25+
print(s)
26+
27+
28+
app=QApplication(sys.argv)
29+
w=MainWindow()
30+
w.show()
31+
app.exec()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
importsys
2+
3+
fromPyQt5.QtWidgetsimportQApplication,QListWidget,QMainWindow
4+
5+
6+
classMainWindow(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+
defindex_changed(self,i):
21+
print(i.text())
22+
23+
deftext_changed(self,s):
24+
print(s)
25+
26+
27+
app=QApplication(sys.argv)
28+
w=MainWindow()
29+
w.show()
30+
app.exec()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
importsys
2+
3+
fromPyQt5.QtWidgetsimportQApplication,QLineEdit,QMainWindow
4+
5+
6+
classMainWindow(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+
defreturn_pressed(self):
27+
print("Return pressed!")
28+
self.centralWidget().setText("BOOM!")
29+
30+
defselection_changed(self):
31+
print("Selection changed")
32+
print(self.centralWidget().selectedText())
33+
34+
deftext_changed(self,s):
35+
print("Text changed...")
36+
print(s)
37+
38+
deftext_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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
importsys
2+
3+
fromPyQt5.QtWidgetsimportQApplication,QMainWindow,QSpinBox
4+
5+
6+
classMainWindow(QMainWindow):
7+
def__init__(self):
8+
super().__init__()
9+
10+
self.setWindowTitle("My App")
11+
12+
widget=QSpinBox()
13+
# Or: widget = QDoubleSpinBox()
14+
15+
widget.setMinimum(-9)
16+
widget.setMaximum(3)
17+
# Or: widget.setRange(-9, 3)
18+
19+
widget.setPrefix("$")
20+
widget.setSuffix("c")
21+
widget.setSingleStep(3)# Or e.g. 3.0 for QDoubleSpinBox
22+
widget.valueChanged.connect(self.value_changed)
23+
widget.textChanged.connect(self.value_changed_str)
24+
25+
self.setCentralWidget(widget)
26+
27+
defvalue_changed(self,i):
28+
print(i)
29+
30+
defvalue_changed_str(self,s):
31+
print(s)
32+
33+
34+
app=QApplication(sys.argv)
35+
w=MainWindow()
36+
w.show()
37+
app.exec()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp