鱼C论坛

 找回密码
 立即注册
查看: 2618|回复: 2

[作品展示] 学习PyQt5过程中做的小玩意

[复制链接]
发表于 2022-8-6 20:18:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 星诺爸爸 于 2022-8-7 18:25 编辑

最近要在单位做点小工具供同事们使用,遂开始自学PyQt5。学习过程中也是吃饱了撑的做了一个卦象显示的小玩意,大神勿笑~~




  1. import random
  2. from gua import Ui_guaWindow
  3. import sys
  4. from PyQt5.QtWidgets import QApplication, QMainWindow
  5. from PyQt5.QtGui import QTextCursor


  6. class GuaXiang(QMainWindow, Ui_guaWindow):
  7.     def __init__(self):
  8.         super(GuaXiang, self).__init__()
  9.         self.setupUi(self)
  10.         self.initUI()

  11.     def initUI(self):
  12.         self.pushButton.clicked.connect(self.mainprog)
  13.         self.textEdit.setText('六爻')
  14.         self.textEdit.moveCursor(QTextCursor.End)

  15.     def mainprog(self):
  16.         s1 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
  17.         s2 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
  18.         s3 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
  19.         s4 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
  20.         s5 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
  21.         s6 = ['☰', '☵', '☶', '☳', '☴', '☲', '☷', '☱']
  22.         gua_up = random.choice(s1) + random.choice(s2) + random.choice(s3) +\
  23.                  random.choice(s4) + random.choice(s5) + random.choice(s6)
  24.         self.textEdit.append(gua_up)



  25. if __name__ == '__main__':
  26.     app = QApplication(sys.argv)
  27.     mywindow = GuaXiang()
  28.     mywindow.show()
  29.     sys.exit(app.exec_())
复制代码




以下是Qt5的界面源码
  1. # -*- coding: utf-8 -*-

  2. # Form implementation generated from reading ui file 'gua.ui'
  3. #
  4. # Created by: PyQt5 UI code generator 5.15.4
  5. #
  6. # WARNING: Any manual changes made to this file will be lost when pyuic5 is
  7. # run again.  Do not edit this file unless you know what you are doing.


  8. from PyQt5 import QtCore, QtGui, QtWidgets


  9. class Ui_guaWindow(object):
  10.     def setupUi(self, guaWindow):
  11.         guaWindow.setObjectName("guaWindow")
  12.         guaWindow.resize(562, 293)
  13.         self.centralwidget = QtWidgets.QWidget(guaWindow)
  14.         self.centralwidget.setObjectName("centralwidget")
  15.         self.pushButton = QtWidgets.QPushButton(self.centralwidget)
  16.         self.pushButton.setGeometry(QtCore.QRect(200, 180, 141, 61))
  17.         self.pushButton.setObjectName("pushButton")
  18.         self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
  19.         self.textEdit.setGeometry(QtCore.QRect(20, 20, 521, 101))
  20.         font = QtGui.QFont()
  21.         font.setFamily("Arial")
  22.         font.setPointSize(60)
  23.         font.setKerning(True)
  24.         self.textEdit.setFont(font)
  25.         self.textEdit.setObjectName("textEdit")
  26.         guaWindow.setCentralWidget(self.centralwidget)
  27.         self.menubar = QtWidgets.QMenuBar(guaWindow)
  28.         self.menubar.setGeometry(QtCore.QRect(0, 0, 562, 23))
  29.         self.menubar.setObjectName("menubar")
  30.         guaWindow.setMenuBar(self.menubar)
  31.         self.statusbar = QtWidgets.QStatusBar(guaWindow)
  32.         self.statusbar.setObjectName("statusbar")
  33.         guaWindow.setStatusBar(self.statusbar)

  34.         self.retranslateUi(guaWindow)
  35.         QtCore.QMetaObject.connectSlotsByName(guaWindow)

  36.     def retranslateUi(self, guaWindow):
  37.         _translate = QtCore.QCoreApplication.translate
  38.         guaWindow.setWindowTitle(_translate("guaWindow", "MainWindow"))
  39.         self.pushButton.setText(_translate("guaWindow", "显示卦象"))
  40.         self.textEdit.setHtml(_translate("guaWindow", "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n"
  41. "<html><head><meta name="qrichtext" content="1" /><style type="text/css">\n"
  42. "p, li { white-space: pre-wrap; }\n"
  43. "</style></head><body style=" font-family:\'Arial\'; font-size:60pt; font-weight:400; font-style:normal;">\n"
  44. "<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>"))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-8-7 18:24:32 | 显示全部楼层
hrpzcf 发表于 2022-8-7 00:00
如果我没猜错的话,你应该是少放了个界面布局源码。

哈哈哈,抱歉抱歉
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-8-7 00:00:20 | 显示全部楼层
如果我没猜错的话,你应该是少放了个界面布局源码。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 17:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表