import sys
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QStackedLayout, QLabel, QPushButton
from PyQt5.Qt import QCursor, QObject
import random
class MyWindow1(QWidget):
def __init__(self):
super().__init__()
QLabel("你喜欢我吗?", self)
self.setStyleSheet("font-size: 70px")
class MyWindow2(QWidget):
def __init__(self):
super().__init__()
QLabel("正好!\n我也喜欢你!", self)
self.setStyleSheet("font-size: 70px")
class MyObject(QObject):
def timerEvent(self, event):
global w
#print(QCursor.pos().x(), '\t',QCursor.pos().y(), w.x(), w.y())
if QCursor.pos().x() > w.x() + 10 and QCursor.pos().x() < w.x() + 200 and QCursor.pos().y() > w.y() + 200 and QCursor.pos().y() < w.y() + 300:
i = random.random()
w.move(int(1680 * i), int(700 * i))
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Hello World!")
self.setFixedSize(400,300)
self.set_ui()
def set_ui(self):
container = QVBoxLayout()
if True:
win1 = MyWindow1()
win2 = MyWindow2()
self.stacket_layout = QStackedLayout()
self.stacket_layout.addWidget(win1)
self.stacket_layout.addWidget(win2)
widget = QWidget()
widget.setLayout(self.stacket_layout)
widget.setStyleSheet("background-color: pink")
btn1 = QPushButton("不喜欢")
btn2 = QPushButton("喜欢!!!地不得了")
self.setStyleSheet("font-size: 18px")
btn1.setFixedHeight(80)
btn2.setFixedHeight(80)
btn2.clicked.connect(self.btn2_clicked)
H_Layout = QHBoxLayout()
H_Layout.addWidget(btn1)
H_Layout.addWidget(btn2)
container.addWidget(widget)
container.addLayout(H_Layout)
self.setLayout(container)
def btn2_clicked(self):
self.stacket_layout.setCurrentIndex(1)
print('抽屉2')
if __name__ == "__main__":
app = QApplication(sys.argv) # 创建应用程序
w = MyWindow() # 创建Widget 界面
w.show() # 显示界面
obj = MyObject()
timer_id = obj.startTimer(100) # 每隔1s,执行
sys.exit(app.exec_()) # 进入死循环
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
c99.你喜欢我吗.zip (3个子文件)
c99.你喜欢我吗.jpg 16KB
c99.你喜欢我吗.py 3KB
c99.你喜欢我吗.exe 75.72MB
共 3 条
- 1
宠我爱我1314
- 粉丝: 10
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0