最近一直在被抖音视频的表白程序刷屏,之前小编也收到过一个VB编写一个表白程序
网上也流传过很多类似的表白程序,但是基本上都是由VB或者易语言编写的。
难道我大Python不能写出这样的程序来么?
人生苦短,我用Python,难道是开玩笑的?!肯定是可以编写出来的!
效果图:
如果你要点击关闭的话,是关不掉的哟
如果点击考虑考虑的话
主要用到的是pyqt5
素材是一张800*800的表情包
完整代码
import sys
from PyQt5 import QtWidgets
from PyQt5.QtGui import QFont,QIcon
from PyQt5 import QtGui,QtCore
import random
class MessageBox(QtWidgets.QWidget):
CloseAllowed=0
def __init__(self,parent = None):
QtWidgets.QWidget.__init__(self)
self.setGeometry(300, 300, 800,800)
self.center()
self.setFixedSize(self.width(),self.height());
self.setWindowTitle(u'表白神器 by Python学习群:125240963')
self.setWindowIcon(QIcon('rose.png'))
self.setToolTip(u'Python学习群:125240963获取源码')
QtWidgets.QToolTip.setFont(QFont('华文楷体', 10))
self.label1 = QtWidgets.QLabel(u'小姐姐,观察你很久了!', self)
self.label1.move(150, 40)
self.label1.setFont(QFont("Timers", 20));
self.label2= QtWidgets.QLabel(u'做我女朋友好不好?', self)
self.label2.move(150, 100)
self.label2.setFont(QFont("Timers", 20));
self.window_pale = QtGui.QPalette()
self.window_pale.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap("biu.jpg")))
self.setPalette(self.window_pale)
self.buttonOK = QtWidgets.QPushButton(u'同意',self)
self.buttonOK.setFocusPolicy(QtCore.Qt.NoFocus)
self.buttonOK.move(50, 700)
self.buttonOK.clicked.connect(self.showDialogOK)
self.buttonE = QtWidgets.QPushButton(u'考虑考虑',self)
self.buttonE.setFocusPolicy(QtCore.Qt.NoFocus)
self.buttonE.move(330, 700)
self.buttonE.clicked.connect(self.showDialogEE)
self.buttonNO = QtWidgets.QPushButton(u'拒绝',self)
self.buttonNO.setFocusPolicy(QtCore.Qt.NoFocus)
self.buttonNO.move(610, 700)
self.buttonNO.clicked.connect(self.showDialogNO)
def showDialogOK(self):
QtWidgets.QMessageBox.information(self, "欧耶", "爱你,么么么么么么么哒~~~", QtWidgets.QMessageBox.Ok)
self.CloseAllowed = 1
def showDialogEE(self):
QtWidgets.QMessageBox.information(self, "别纠结了", "你完了,你妈让你嫁给我", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "你爸也是这么说的", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "你奶奶也让你嫁给我", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "你哥哥也同意了,你全家都同意", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "你闺蜜说嫁给我没错", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "你爸说不同意就打你", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "接受现实吧,我会对你好的", QtWidgets.QMessageBox.Ok)
QtWidgets.QMessageBox.information(self, "别纠结了", "你都是我的人了", QtWidgets.QMessageBox.Ok)
def showDialogNO
(self):
self.q = random.randint(0, 650)
self.w = random.randint(150, 650)
self.buttonNO.move(self.q, self.w)
def closeEvent(self,event):
if self.CloseAllowed==1:
event.accept()
else:
QtWidgets.QMessageBox.information(self, "未作回应", "小姐姐,请不要逃避!", QtWidgets.QMessageBox.Ok)
event.ignore()
def center(self):
screen=QtWidgets.QDesktopWidget().screenGeometry()
size=self.geometry()
self.move((screen.width()-size.width())/2,(screen.height()-size.height())/2)
app=QtWidgets.QApplication(sys.argv)
window=MessageBox()
window.show()
sys.exit(app.exec_())
想要发给你自己喜欢的人,肯定是需要打包成exe的呀
"""
__title__ = '将calculator项目转换为exe文件'
__author__ = '遂越净郝'
"""
from PyInstaller.__main__ import run
if __name__ == '__main__':
opts = ['douyin.py', '-w', '--onefile']
run(opts)
所以你准备好了么!
本文作者:遂越净郝
源自:
https://zhuanlan.zhihu.com/p/38284396