|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 星诺爸爸 于 2022-8-7 18:25 编辑
最近要在单位做点小工具供同事们使用,遂开始自学PyQt5。学习过程中也是吃饱了撑的做了一个卦象显示的小玩意,大神勿笑~~
import random
from gua import Ui_guaWindow
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QTextCursor
class GuaXiang(QMainWindow, Ui_guaWindow):
def __init__(self):
super(GuaXiang, self).__init__()
self.setupUi(self)
self.initUI()
def initUI(self):
self.pushButton.clicked.connect(self.mainprog)
self.textEdit.setText('六爻')
self.textEdit.moveCursor(QTextCursor.End)
def mainprog(self):
s1 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
s2 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
s3 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
s4 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
s5 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
s6 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
gua_up = random.choice(s1) + random.choice(s2) + random.choice(s3) +\
random.choice(s4) + random.choice(s5) + random.choice(s6)
self.textEdit.append(gua_up)
if __name__ == '__main__':
app = QApplication(sys.argv)
mywindow = GuaXiang()
mywindow.show()
sys.exit(app.exec_())
以下是Qt5的界面源码# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gua.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_guaWindow(object):
def setupUi(self, guaWindow):
guaWindow.setObjectName("guaWindow")
guaWindow.resize(562, 293)
self.centralwidget = QtWidgets.QWidget(guaWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(200, 180, 141, 61))
self.pushButton.setObjectName("pushButton")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(20, 20, 521, 101))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(60)
font.setKerning(True)
self.textEdit.setFont(font)
self.textEdit.setObjectName("textEdit")
guaWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(guaWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 562, 23))
self.menubar.setObjectName("menubar")
guaWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(guaWindow)
self.statusbar.setObjectName("statusbar")
guaWindow.setStatusBar(self.statusbar)
self.retranslateUi(guaWindow)
QtCore.QMetaObject.connectSlotsByName(guaWindow)
def retranslateUi(self, guaWindow):
_translate = QtCore.QCoreApplication.translate
guaWindow.setWindowTitle(_translate("guaWindow", "MainWindow"))
self.pushButton.setText(_translate("guaWindow", "显示卦象"))
self.textEdit.setHtml(_translate("guaWindow", "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n"
"<html><head><meta name="qrichtext" content="1" /><style type="text/css">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=" font-family:\'Arial\'; font-size:60pt; font-weight:400; font-style:normal;">\n"
"<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>"))
|
|