本帖最后由 FUEL 于 2023-6-2 22:22 编辑
代码附上[Python] 纯文本查看 复制代码 from PyQt5 import Qt
import sys
from turtle import *
import time
class MyButton1(Qt.QPushButton):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.move(100, 160)
self.setText("喜欢")
self.setMouseTracking(True)
self.setStyleSheet("font:15pt")
def mouseMoveEvent(self, e):
super().mouseMoveEvent(e)
self.setText("喜欢")
button2.setText("不喜欢")
def leaveEvent(self, a0):
super().leaveEvent(a0)
self.setText("喜欢")
button2.setText("不喜欢")
def mousePressEvent(self, e):
super().mousePressEvent(e)
label1.setText("我也喜欢你")
label1.adjustSize()
label1.move(180, 100)
button1.setHidden(True)
button2.setHidden(True)
label2.setHidden(False)
label2.countdown()
label2.setHidden(True)
PaintLove().love()
class MyButton2(Qt.QPushButton):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setText("不喜欢")
self.move(300, 160)
self.setMouseTracking(True)
self.setStyleSheet("font:15pt")
def mouseMoveEvent(self, e):
super().mouseMoveEvent(e)
self.setText("喜欢")
button1.setText("不喜欢")
def leaveEvent(self, a0):
super().leaveEvent(a0)
self.setText("不喜欢")
button1.setText("喜欢")
def mousePressEvent(self, e):
super().mousePressEvent(e)
label1.setText("我也喜欢你")
label1.adjustSize()
label1.move(180, 100)
button1.setHidden(True)
button2.setHidden(True)
label2.setHidden(False)
label2.countdown()
label2.setHidden(True)
PaintLove().love()
class MyLabel1(Qt.QLabel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setText("你喜欢我吗?")
self.move(180, 60)
self.setStyleSheet("font:15pt")
class MyLabel2(Qt.QLabel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setText("3")
self.move(230, 180)
self.setStyleSheet("font:20pt")
self.adjustSize()
self.setHidden(True)
def countdown(self):
for i in range(1, 4):
time.sleep(1)
self.setText(str(3 - i))
self.repaint()
class PaintLove:
def painting(self):
for i in range(200):
right(1)
forward(1)
def love(self):
pensize(2)
speed(50)
color("black", "red")
begin_fill()
left(140)
forward(111.65)
self.painting()
left(120)
self.painting()
forward(111.65)
end_fill()
hideturtle()
done()
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = Qt.QWidget()
window.setFixedSize(500, 300)
window.setWindowTitle("表白小程序")
label1 = MyLabel1(window)
label2 = MyLabel2(window)
button1 = MyButton1(window)
button2 = MyButton2(window)
window.show()
sys.exit(app.exec_()) |