mirror of
https://github.com/pythonguis/pythonguis-examples.git
synced 2025-02-03 17:13:00 +08:00
Renamed
This commit is contained in:
parent
d2fe7af757
commit
1e600db0a2
63
pyqt5/tutorials/basic-widgets/example_001.py
Normal file
63
pyqt5/tutorials/basic-widgets/example_001.py
Normal file
@ -0,0 +1,63 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QDateEdit,
|
||||
QDateTimeEdit,
|
||||
QDial,
|
||||
QDoubleSpinBox,
|
||||
QFontComboBox,
|
||||
QLabel,
|
||||
QLCDNumber,
|
||||
QLineEdit,
|
||||
QMainWindow,
|
||||
QProgressBar,
|
||||
QPushButton,
|
||||
QRadioButton,
|
||||
QSlider,
|
||||
QSpinBox,
|
||||
QTimeEdit,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Widgets App")
|
||||
|
||||
layout = QVBoxLayout()
|
||||
widgets = [
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QDateEdit,
|
||||
QDateTimeEdit,
|
||||
QDial,
|
||||
QDoubleSpinBox,
|
||||
QFontComboBox,
|
||||
QLCDNumber,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QProgressBar,
|
||||
QPushButton,
|
||||
QRadioButton,
|
||||
QSlider,
|
||||
QSpinBox,
|
||||
QTimeEdit,
|
||||
]
|
||||
|
||||
for w in widgets:
|
||||
layout.addWidget(w())
|
||||
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
app.exec()
|
29
pyqt5/tutorials/basic-widgets/example_002.py
Normal file
29
pyqt5/tutorials/basic-widgets/example_002.py
Normal file
@ -0,0 +1,29 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QDial,
|
||||
QDoubleSpinBox,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QListWidget,
|
||||
QMainWindow,
|
||||
QSlider,
|
||||
QSpinBox,
|
||||
)
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
26
pyqt5/tutorials/basic-widgets/example_003.py
Normal file
26
pyqt5/tutorials/basic-widgets/example_003.py
Normal file
@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QLabel("Hello")
|
||||
font = widget.font()
|
||||
font.setPointSize(30)
|
||||
widget.setFont(font)
|
||||
widget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
26
pyqt5/tutorials/basic-widgets/example_004.py
Normal file
26
pyqt5/tutorials/basic-widgets/example_004.py
Normal file
@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QLabel()
|
||||
widget.setPixmap(QPixmap("otje.jpg"))
|
||||
widget.setScaledContents(True)
|
||||
widget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
28
pyqt5/tutorials/basic-widgets/example_005.py
Normal file
28
pyqt5/tutorials/basic-widgets/example_005.py
Normal file
@ -0,0 +1,28 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QApplication, QCheckBox, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QCheckBox()
|
||||
widget.setCheckState(Qt.Checked)
|
||||
|
||||
widget.stateChanged.connect(self.show_state)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def show_state(self, s):
|
||||
print(s == Qt.Checked)
|
||||
print(s)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
31
pyqt5/tutorials/basic-widgets/example_006.py
Normal file
31
pyqt5/tutorials/basic-widgets/example_006.py
Normal file
@ -0,0 +1,31 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QComboBox, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QComboBox()
|
||||
widget.addItems(["One", "Two", "Three"])
|
||||
|
||||
widget.currentIndexChanged.connect(self.index_changed)
|
||||
|
||||
widget.currentTextChanged.connect(self.text_changed)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def index_changed(self, i):
|
||||
print(i)
|
||||
|
||||
def text_changed(self, s):
|
||||
print(s)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
30
pyqt5/tutorials/basic-widgets/example_007.py
Normal file
30
pyqt5/tutorials/basic-widgets/example_007.py
Normal file
@ -0,0 +1,30 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QListWidget, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QListWidget()
|
||||
widget.addItems(["One", "Two", "Three"])
|
||||
|
||||
widget.currentItemChanged.connect(self.index_changed)
|
||||
widget.currentTextChanged.connect(self.text_changed)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def index_changed(self, i):
|
||||
print(i.text())
|
||||
|
||||
def text_changed(self, s):
|
||||
print(s)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
46
pyqt5/tutorials/basic-widgets/example_008.py
Normal file
46
pyqt5/tutorials/basic-widgets/example_008.py
Normal file
@ -0,0 +1,46 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QLineEdit, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QLineEdit()
|
||||
widget.setMaxLength(10)
|
||||
widget.setPlaceholderText("Enter your text")
|
||||
|
||||
# widget.setReadOnly(True) # uncomment this to make readonly
|
||||
|
||||
widget.returnPressed.connect(self.return_pressed)
|
||||
widget.selectionChanged.connect(self.selection_changed)
|
||||
widget.textChanged.connect(self.text_changed)
|
||||
widget.textEdited.connect(self.text_edited)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def return_pressed(self):
|
||||
print("Return pressed!")
|
||||
self.centralWidget().setText("BOOM!")
|
||||
|
||||
def selection_changed(self):
|
||||
print("Selection changed")
|
||||
print(self.centralWidget().selectedText())
|
||||
|
||||
def text_changed(self, s):
|
||||
print("Text changed...")
|
||||
print(s)
|
||||
|
||||
def text_edited(self, s):
|
||||
print("Text edited...")
|
||||
print(s)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
37
pyqt5/tutorials/basic-widgets/example_009.py
Normal file
37
pyqt5/tutorials/basic-widgets/example_009.py
Normal file
@ -0,0 +1,37 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QSpinBox
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QSpinBox()
|
||||
# Or: widget = QDoubleSpinBox()
|
||||
|
||||
widget.setMinimum(-9)
|
||||
widget.setMaximum(3)
|
||||
# Or: widget.setRange(-9, 3)
|
||||
|
||||
widget.setPrefix("$")
|
||||
widget.setSuffix("c")
|
||||
widget.setSingleStep(3) # Or e.g. 3.0 for QDoubleSpinBox
|
||||
widget.valueChanged.connect(self.value_changed)
|
||||
widget.textChanged.connect(self.value_changed_str)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def value_changed(self, i):
|
||||
print(i)
|
||||
|
||||
def value_changed_str(self, s):
|
||||
print(s)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
43
pyqt5/tutorials/basic-widgets/example_010.py
Normal file
43
pyqt5/tutorials/basic-widgets/example_010.py
Normal file
@ -0,0 +1,43 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QSlider
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QSlider()
|
||||
|
||||
widget.setMinimum(-10)
|
||||
widget.setMaximum(3)
|
||||
# Or: widget.setRange(-10,3)
|
||||
|
||||
widget.setSingleStep(3)
|
||||
|
||||
widget.valueChanged.connect(self.value_changed)
|
||||
widget.sliderMoved.connect(self.slider_position)
|
||||
widget.sliderPressed.connect(self.slider_pressed)
|
||||
widget.sliderReleased.connect(self.slider_released)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def value_changed(self, i):
|
||||
print(i)
|
||||
|
||||
def slider_position(self, p):
|
||||
print("Position", p)
|
||||
|
||||
def slider_pressed(self):
|
||||
print("Pressed!")
|
||||
|
||||
def slider_released(self):
|
||||
print("Released")
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
39
pyqt5/tutorials/basic-widgets/example_011.py
Normal file
39
pyqt5/tutorials/basic-widgets/example_011.py
Normal file
@ -0,0 +1,39 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QDial, QMainWindow
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
|
||||
widget = QDial()
|
||||
widget.setRange(-10, 100)
|
||||
widget.setSingleStep(1)
|
||||
|
||||
widget.valueChanged.connect(self.value_changed)
|
||||
widget.sliderMoved.connect(self.slider_position)
|
||||
widget.sliderPressed.connect(self.slider_pressed)
|
||||
widget.sliderReleased.connect(self.slider_released)
|
||||
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def value_changed(self, i):
|
||||
print(i)
|
||||
|
||||
def slider_position(self, p):
|
||||
print("Position", p)
|
||||
|
||||
def slider_pressed(self):
|
||||
print("Pressed!")
|
||||
|
||||
def slider_released(self):
|
||||
print("Released")
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
app.exec()
|
Loading…
x
Reference in New Issue
Block a user