- 使用PyQT的浮动tip
- 使用PyQT的toolbar
- 使用PyQT的浮动tool
- 使用PyQT的菜单栏
- 使用PyQT的tab切换组件
# 鼠标移动到按钮上方,就会现实tip
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
button = QPushButton("Button")
# 给按钮设置传统的tip
button.setToolTip("This is a text")
layout.addWidget(button, 0, 0)
button = QPushButton("Button")
# 给按钮设置HTML格式的tip
button.setToolTip("HTML can be shown too..")
layout.addWidget(button, 1, 0)
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
# 初始化toolbar
toolBar = QToolBar()
layout.addWidget(toolBar)
# 网toolbar中添加按钮
toolButton = QToolButton()
toolButton.setText("Apple")
toolButton.setCheckable(True)
toolButton.setAutoExclusive(True)
toolBar.addWidget(toolButton)
toolButton = QToolButton()
toolButton.setText("Orange")
toolButton.setCheckable(True)
toolButton.setAutoExclusive(True)
toolBar.addWidget(toolButton)
# 添加文本输入框到窗口
tbox = QPlainTextEdit()
layout.addWidget(tbox)
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
from PyQt5.QtWidgets import *
import sys
# addItem()
# count()
# currentIndex()
# insertItem()
# itemToolTip()
# itemText()
# itemIcon()
# isItemEnabled()
# removeItem()
# setItemEnabled()
# setItemIcon()
# setItemText()
# setItemToolTip()
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
# 添加子项到toolbox
toolbox = QToolBox()
layout.addWidget(toolbox, 0, 0)
label = QLabel()
toolbox.addItem(label, "Students")
label = QLabel()
toolbox.addItem(label, "Teachers")
label = QLabel()
toolbox.addItem(label, "Directors")
# 现实toolbox有多少个子项
print(toolbox.count())
# 设置无法编辑的项
toolbox.setItemEnabled(0, False)
# 设置鼠标移动到tool时的tip
toolbox.setItemToolTip(0, "This is a tooltip")
# 获取状态
print(toolbox.isItemEnabled(0))
print(toolbox.isItemEnabled(1))
# 插入一个新的item
item = QLabel()
toolbox.insertItem(1, item, "Python")
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
# 创建菜单
menubar = QMenuBar()
layout.addWidget(menubar, 0, 0)
actionFile = menubar.addMenu("File")
# 给File这个按钮添加子项
actionFile.addAction("New")
actionFile.addAction("Open")
actionFile.addAction("Save")
actionFile.addSeparator()
actionFile.addAction("Quit")
menubar.addMenu("Edit")
menubar.addMenu("View")
menubar.addMenu("Help")
# 添加文本输入框
tbox = QPlainTextEdit()
layout.addWidget(tbox, 1, 0)
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
label1 = QLabel("Widget in Tab 1.")
label2 = QLabel("Widget in Tab 2.")
# 初始化tab组件
tabwidget = QTabWidget()
# 把label1放在tab1
tabwidget.addTab(label1, "Tab 1")
# 把label2放在tab2
tabwidget.addTab(label2, "Tab 2")
layout.addWidget(tabwidget, 0, 0)
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())



