PyQt5最全74 布局之技巧让按钮永远在窗口的右下角
import sys
from PyQt5.QtWidgets import *
class RightBottomButton(QWidget):
"""
小技巧:让按钮永远在窗口的右下角
"""
def __init__(self):
super(RightBottomButton, self).__init__()
self.setWindowTitle('让按钮永远在右下角')
self.resize(400, 300)
okButton = QPushButton('确定')
cancelButton = QPushButton('取消')
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton)
vbox = QVBoxLayout()
btn1 = QPushButton('按钮1')
btn2 = QPushButton('按钮2')
btn3 = QPushButton('按钮3')
vbox.addStretch(1)
vbox.addWidget(btn1)
vbox.addWidget(btn2)
vbox.addWidget(btn3)
vbox.addStretch(1)
vbox.addLayout(hbox)
self.setLayout(vbox)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = RightBottomButton()
print(main.__doc__)
main.show()
sys.exit(app.exec_())
结果
随意拖动窗口大小以后,
|