時(shí)間段【1】 9:00-20:00 from PyQt5.QtWidgets import QApplication,QWidget import sys if __name__ == "__main__": app = QApplication(sys.argv) window = QWidget() window.resize(300,200) window.move(300,300) window.setWindowTitle('測試窗口') window.show() sys.exit(app.exec_())
from PyQt5.QtWidgets import QApplication,QWidget from PyQt5.QtGui import QIcon import sys class Example(QWidget): def __init__(self): #調(diào)用父類的構(gòu)造方法 super().__init__() self.initUI() def initUI(self): #設(shè)置窗口大小和位置 self.setGeometry(300,300,300,200) #設(shè)置窗口標(biāo)題 self.setWindowTitle('圖標(biāo)') #修改圖標(biāo) self.setWindowIcon(QIcon('python\day08\m1.png')) #顯示圖標(biāo) self.show() if __name__ == "__main__": app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) from PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QToolTip from PyQt5.QtGui import QFont import sys class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): #設(shè)置提示的字體 pixel px QToolTip.setFont(QFont('微軟雅黑',10)) #創(chuàng)建提示 self.setToolTip('這是一個(gè)<b>QWidget</b>組件') #創(chuàng)建按鈕 btn = QPushButton('按鈕',self) #創(chuàng)建提示 btn.setToolTip('這是一個(gè)<i>按鈕</i>組件') #移動(dòng)按鈕的位置 btn.move(100,100)
self.setGeometry(300,300,300,200) self.setWindowTitle('提示消息') self.show() if __name__ == "__main__": app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) from PyQt5.QtWidgets import QApplication,QWidget,QPushButton from PyQt5.QtCore import QCoreApplication import sys class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): #創(chuàng)建按鈕 btn = QPushButton('按鈕',self) #移動(dòng)按鈕位置 btn.move(100,100) #給按鈕綁定功能 # btn.clicked.connect(self.f) btn.clicked.connect(QCoreApplication.instance().quit)
self.setGeometry(300,300,300,200) self.setWindowTitle('給按鈕綁定功能') self.show() def f(self): print('測試按鈕功能!') if __name__ == "__main__": app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) from PyQt5.QtWidgets import QApplication,QWidget,QMessageBox import sys class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300,300,300,200) self.setWindowTitle('消息窗口演示') self.show()
組建的定位方式: 絕對定位,當(dāng)調(diào)整窗口時(shí),組建的大小和位置時(shí)不變 框式布局 ''' from PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QHBoxLayout,QVBoxLayout import sys class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): #創(chuàng)建兩個(gè)按鈕 ok = QPushButton('OK') cancel = QPushButton('Cancel') #創(chuàng)建水平布局 hbox = QHBoxLayout() hbox.addStretch(1) hbox.addWidget(ok) hbox.addWidget(cancel) #創(chuàng)建垂直布局 vbox = QVBoxLayout() vbox.addStretch(15) vbox.addLayout(hbox) vbox.addStretch(1)
self.setLayout(vbox) self.setGeometry(300,300,300,200) self.setWindowTitle('框式布局') self.show() if __name__ == "__main__": app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
時(shí)間段【2】 21:00-21:00 寫作業(yè),練習(xí)今天的操作
|