上傳檔案到「pyqt5/CODE/元件使用範例」
This commit is contained in:
parent
f72545ed0c
commit
16b667068f
35
pyqt5/CODE/元件使用範例/qt04_QStatusBar.py
Normal file
35
pyqt5/CODE/元件使用範例/qt04_QStatusBar.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中QStatusBar範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class StatusDemo(QMainWindow):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(StatusDemo, self).__init__(parent)
|
||||||
|
bar = self.menuBar()
|
||||||
|
file = bar.addMenu("File")
|
||||||
|
file.addAction("Show")
|
||||||
|
file.triggered[QAction].connect(self.processTrigger)
|
||||||
|
self.setCentralWidget(QTextEdit())
|
||||||
|
self.statusBar= QStatusBar()
|
||||||
|
self.setWindowTitle("QStatusBar範例")
|
||||||
|
self.setStatusBar(self.statusBar)
|
||||||
|
|
||||||
|
def processTrigger(self,q):
|
||||||
|
if (q.text()=="Show"):
|
||||||
|
self.statusBar.showMessage(q.text()+" 功能表選項被點擊了",5000)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = StatusDemo()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
58
pyqt5/CODE/元件使用範例/qt04_QTabWidget.py
Normal file
58
pyqt5/CODE/元件使用範例/qt04_QTabWidget.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中QTabWidget範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class TabDemo(QTabWidget):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(TabDemo, self).__init__(parent)
|
||||||
|
self.tab1 = QWidget()
|
||||||
|
self.tab2 = QWidget()
|
||||||
|
self.tab3 = QWidget()
|
||||||
|
self.addTab(self.tab1,"Tab 1")
|
||||||
|
self.addTab(self.tab2,"Tab 2")
|
||||||
|
self.addTab(self.tab3,"Tab 3")
|
||||||
|
self.tab1UI()
|
||||||
|
self.tab2UI()
|
||||||
|
self.tab3UI()
|
||||||
|
self.setWindowTitle("Tab範例")
|
||||||
|
|
||||||
|
def tab1UI(self):
|
||||||
|
layout = QFormLayout()
|
||||||
|
layout.addRow("姓名",QLineEdit())
|
||||||
|
layout.addRow("地址",QLineEdit())
|
||||||
|
self.setTabText(0,"聯絡方式")
|
||||||
|
self.tab1.setLayout(layout)
|
||||||
|
|
||||||
|
def tab2UI(self):
|
||||||
|
layout = QFormLayout()
|
||||||
|
sex = QHBoxLayout()
|
||||||
|
sex.addWidget(QRadioButton("男"))
|
||||||
|
sex.addWidget(QRadioButton("女"))
|
||||||
|
layout.addRow(QLabel("性別"),sex)
|
||||||
|
layout.addRow("生日",QLineEdit())
|
||||||
|
self.setTabText(1,"個人詳細資訊")
|
||||||
|
self.tab2.setLayout(layout)
|
||||||
|
|
||||||
|
def tab3UI(self):
|
||||||
|
layout=QHBoxLayout()
|
||||||
|
layout.addWidget(QLabel("科目"))
|
||||||
|
layout.addWidget(QCheckBox("物理"))
|
||||||
|
layout.addWidget(QCheckBox("數學"))
|
||||||
|
self.setTabText(2,"教育程度")
|
||||||
|
self.tab3.setLayout(layout)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = TabDemo()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
38
pyqt5/CODE/元件使用範例/qt04_textEdit.py
Normal file
38
pyqt5/CODE/元件使用範例/qt04_textEdit.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中 QTextEdit範例
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QApplication, QWidget , QTextEdit, QVBoxLayout , QPushButton
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class TextEditDemo(QWidget):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(TextEditDemo, self).__init__(parent)
|
||||||
|
self.setWindowTitle("QTextEdit 範例")
|
||||||
|
self.resize(300, 270)
|
||||||
|
self.textEdit = QTextEdit( )
|
||||||
|
self.btnPress1 = QPushButton("顯示文字")
|
||||||
|
self.btnPress2 = QPushButton("顯示HTML")
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
layout.addWidget(self.textEdit)
|
||||||
|
layout.addWidget(self.btnPress1)
|
||||||
|
layout.addWidget(self.btnPress2)
|
||||||
|
self.setLayout(layout)
|
||||||
|
self.btnPress1.clicked.connect(self.btnPress1_Clicked)
|
||||||
|
self.btnPress2.clicked.connect(self.btnPress2_Clicked)
|
||||||
|
|
||||||
|
def btnPress1_Clicked(self):
|
||||||
|
self.textEdit.setPlainText("Hello PyQt5!\n點擊按鈕")
|
||||||
|
|
||||||
|
def btnPress2_Clicked(self):
|
||||||
|
self.textEdit.setHtml("<font color='red' size='6'><red>Hello PyQt5!\n點擊按鈕。</font>")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
win = TextEditDemo()
|
||||||
|
win.show()
|
||||||
|
sys.exit(app.exec_())
|
46
pyqt5/CODE/元件使用範例/qt401_widgetGeometry.py
Normal file
46
pyqt5/CODE/元件使用範例/qt401_widgetGeometry.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中坐標系統
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QApplication ,QWidget ,QPushButton
|
||||||
|
import sys
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
widget = QWidget()
|
||||||
|
btn = QPushButton( widget )
|
||||||
|
btn.setText("Button")
|
||||||
|
#以QWidget左上角為(0, 0)點
|
||||||
|
btn.move(20, 20)
|
||||||
|
#不同的作業系統可能對視窗的最小寬度有限制,若設定的寬度小於規定值,則以規定值為主
|
||||||
|
widget.resize(300, 200)
|
||||||
|
#以螢幕左上角為(0, 0)點
|
||||||
|
widget.move(250, 200)
|
||||||
|
|
||||||
|
widget.setWindowTitle('PyQt坐標系統範例')
|
||||||
|
widget.show()
|
||||||
|
print("#1 QWidget")
|
||||||
|
print("widget.x()=%d" % widget.x() )
|
||||||
|
print("widget.y()=%d" % widget.y() )
|
||||||
|
print("widget.width()=%d" % widget.width() )
|
||||||
|
print("widget.height()=%d" % widget.height() )
|
||||||
|
|
||||||
|
print("#2 QWidget.geometry")
|
||||||
|
print("widget.geometry().x()=%d" % widget.geometry().x() )
|
||||||
|
print("widget.geometry().y()=%d" % widget.geometry().y() )
|
||||||
|
print("widget.geometry().width()=%d" % widget.geometry().width() )
|
||||||
|
print("widget.geometry().height()=%d" % widget.geometry().height() )
|
||||||
|
print("widget.size().width() =%d" % widget.size().width() )
|
||||||
|
print("widget.size().height() =%d" % widget.size().height() )
|
||||||
|
|
||||||
|
print("#3 QWidget.frameGeometry")
|
||||||
|
print("widget.frameGeometry().width()=%d" % widget.frameGeometry().width() )
|
||||||
|
print("widget.frameGeometry().height()=%d" % widget.frameGeometry().height() )
|
||||||
|
print("widget.pos().x()=%d" % widget.pos().x() )
|
||||||
|
print("widget.pos().y()=%d" % widget.pos().y() )
|
||||||
|
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
18
pyqt5/CODE/元件使用範例/qt402_FirstPyQt.py
Normal file
18
pyqt5/CODE/元件使用範例/qt402_FirstPyQt.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
【簡介】
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication, QWidget
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
window = QWidget()
|
||||||
|
window.resize(300, 200)
|
||||||
|
window.move(250, 150)
|
||||||
|
window.setWindowTitle('Hello PyQt5')
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec_())
|
Loading…
Reference in New Issue
Block a user