• pyqt5 处理传入 接受信号练习


    1. # -*- coding: utf-8 -*-
    2. # Form implementation generated from reading ui file 'testtwo.ui'
    3. #
    4. # Created by: PyQt5 UI code generator 5.15.7
    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. from PyQt5.QtCore import Qt
    10. class Ui_MainWindow(object):
    11. def setupUi(self, MainWindow):
    12. MainWindow.setObjectName("MainWindow")
    13. MainWindow.resize(800, 600)
    14. self.centralwidget = QtWidgets.QWidget(MainWindow)
    15. self.centralwidget.setObjectName("centralwidget")
    16. self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
    17. self.tabWidget.setGeometry(QtCore.QRect(0, 0, 801, 571))
    18. font = QtGui.QFont()
    19. font.setFamily("Arial")
    20. font.setPointSize(10)
    21. self.tabWidget.setFont(font)
    22. self.tabWidget.setObjectName("tabWidget")
    23. self.tab = QtWidgets.QWidget()
    24. self.tab.setObjectName("tab")
    25. self.checkBox = QtWidgets.QCheckBox(self.tab)
    26. self.checkBox.setGeometry(QtCore.QRect(10, 20, 91, 19))
    27. self.checkBox.setObjectName("checkBox")
    28. self.comboBox = QtWidgets.QComboBox(self.tab)
    29. self.comboBox.setGeometry(QtCore.QRect(10, 60, 87, 22))
    30. self.comboBox.setObjectName("comboBox")
    31. self.dateEdit = QtWidgets.QDateEdit(self.tab)
    32. self.dateEdit.setGeometry(QtCore.QRect(20, 100, 110, 22))
    33. self.dateEdit.setObjectName("dateEdit")
    34. self.dateTimeEdit = QtWidgets.QDateTimeEdit(self.tab)
    35. self.dateTimeEdit.setGeometry(QtCore.QRect(10, 160, 194, 22))
    36. self.dateTimeEdit.setObjectName("dateTimeEdit")
    37. self.tabWidget.addTab(self.tab, "")
    38. self.tab_3 = QtWidgets.QWidget()
    39. self.tab_3.setObjectName("tab_3")
    40. self.dial = QtWidgets.QDial(self.tab_3)
    41. self.dial.setGeometry(QtCore.QRect(50, 80, 50, 64))
    42. self.dial.setObjectName("dial")
    43. self.doubleSpinBox = QtWidgets.QDoubleSpinBox(self.tab_3)
    44. self.doubleSpinBox.setGeometry(QtCore.QRect(40, 190, 70, 22))
    45. self.doubleSpinBox.setObjectName("doubleSpinBox")
    46. self.fontComboBox = QtWidgets.QFontComboBox(self.tab_3)
    47. self.fontComboBox.setGeometry(QtCore.QRect(30, 260, 279, 22))
    48. self.fontComboBox.setObjectName("fontComboBox")
    49. self.lcdNumber = QtWidgets.QLCDNumber(self.tab_3)
    50. self.lcdNumber.setGeometry(QtCore.QRect(40, 310, 64, 23))
    51. self.lcdNumber.setSmallDecimalPoint(True)
    52. self.lcdNumber.setMode(QtWidgets.QLCDNumber.Oct)
    53. self.lcdNumber.setProperty("value", 125.0)
    54. self.lcdNumber.setObjectName("lcdNumber")
    55. self.label = QtWidgets.QLabel(self.tab_3)
    56. self.label.setGeometry(QtCore.QRect(450, 380, 211, 81))
    57. self.label.setObjectName("label")
    58. self.tabWidget.addTab(self.tab_3, "")
    59. self.tab_4 = QtWidgets.QWidget()
    60. self.tab_4.setObjectName("tab_4")
    61. self.lineEdit = QtWidgets.QLineEdit(self.tab_4)
    62. self.lineEdit.setGeometry(QtCore.QRect(40, 50, 113, 21))
    63. self.lineEdit.setObjectName("lineEdit")
    64. self.progressBar = QtWidgets.QProgressBar(self.tab_4)
    65. self.progressBar.setGeometry(QtCore.QRect(40, 180, 118, 23))
    66. self.progressBar.setProperty("value", 50)
    67. self.progressBar.setObjectName("progressBar")
    68. self.pushButton = QtWidgets.QPushButton(self.tab_4)
    69. self.pushButton.setGeometry(QtCore.QRect(40, 260, 93, 28))
    70. self.pushButton.setObjectName("pushButton")
    71. self.radioButton = QtWidgets.QRadioButton(self.tab_4)
    72. self.radioButton.setGeometry(QtCore.QRect(40, 310, 115, 19))
    73. self.radioButton.setObjectName("radioButton")
    74. self.tabWidget.addTab(self.tab_4, "")
    75. self.tab_2 = QtWidgets.QWidget()
    76. self.tab_2.setObjectName("tab_2")
    77. self.horizontalSlider = QtWidgets.QSlider(self.tab_2)
    78. self.horizontalSlider.setGeometry(QtCore.QRect(90, 110, 160, 22))
    79. self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
    80. self.horizontalSlider.setObjectName("horizontalSlider")
    81. self.verticalScrollBar = QtWidgets.QScrollBar(self.tab_2)
    82. self.verticalScrollBar.setGeometry(QtCore.QRect(100, 170, 16, 160))
    83. self.verticalScrollBar.setOrientation(QtCore.Qt.Vertical)
    84. self.verticalScrollBar.setObjectName("verticalScrollBar")
    85. self.verticalSlider = QtWidgets.QSlider(self.tab_2)
    86. self.verticalSlider.setGeometry(QtCore.QRect(440, 100, 22, 160))
    87. self.verticalSlider.setOrientation(QtCore.Qt.Vertical)
    88. self.verticalSlider.setObjectName("verticalSlider")
    89. self.spinBox = QtWidgets.QSpinBox(self.tab_2)
    90. self.spinBox.setGeometry(QtCore.QRect(510, 90, 46, 22))
    91. self.spinBox.setObjectName("spinBox")
    92. self.timeEdit = QtWidgets.QTimeEdit(self.tab_2)
    93. self.timeEdit.setGeometry(QtCore.QRect(480, 330, 118, 22))
    94. self.timeEdit.setObjectName("timeEdit")
    95. self.tabWidget.addTab(self.tab_2, "")
    96. MainWindow.setCentralWidget(self.centralwidget)
    97. self.menubar = QtWidgets.QMenuBar(MainWindow)
    98. self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
    99. self.menubar.setObjectName("menubar")
    100. MainWindow.setMenuBar(self.menubar)
    101. self.statusbar = QtWidgets.QStatusBar(MainWindow)
    102. self.statusbar.setObjectName("statusbar")
    103. MainWindow.setStatusBar(self.statusbar)
    104. self.retranslateUi(MainWindow)
    105. self.tabWidget.setCurrentIndex(1)
    106. QtCore.QMetaObject.connectSlotsByName(MainWindow)
    107. def checkboxshow(self,s):
    108. #self.label.setText(str(s))
    109. if s==0:self.label.setPixmap(QtGui.QPixmap(r"C:\Users\komorip\Desktop\daliy\python\uidesign\iconn\q11.jpg"))
    110. else:
    111. self.label.setText(str(s))
    112. def comboxshow_index(self,i):
    113. print(i)
    114. def comboxshow_text(self,s):
    115. global q #先声明再赋值
    116. q=int(s) #赋值即使同名也会创建局部作用域的变量 所以想要赋值到全局变量必须声明
    117. def compute(self,b,s=1):
    118. self.label.setText(str(b*s))
    119. #print(b*s)
    120. def retranslateUi(self, MainWindow):
    121. _translate = QtCore.QCoreApplication.translate
    122. MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    123. self.checkBox.setText(_translate("MainWindow", "你是猪"))
    124. self.checkBox.setCheckState(Qt.Checked)
    125. self.checkBox.stateChanged.connect(self.checkboxshow)#不带括号
    126. self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", " 1"))
    127. #self.label.setText(_translate("MainWindow", "你是猪"))
    128. #self.label.setPixmap(QtGui.QPixmap(r"C:\Users\komorip\Desktop\daliy\python\uidesign\iconn\q11.jpg"))
    129. self.label.setScaledContents(True)
    130. self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "2"))
    131. self.pushButton.setText(_translate("MainWindow", "PushButton"))
    132. self.radioButton.setText(_translate("MainWindow", "RadioButton"))
    133. self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "3"))
    134. self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "4"))
    135. self.comboBox.addItems(["1","2","3","4","5"])
    136. #self.comboBox.currentIndexChanged.connect(self.comboxshow_index)
    137. #self.comboBox.currentTextChanged.connect(self.comboxshow_text)#传参时使用这一条并且一开始会有一个默认情况设定
    138. if __name__ == "__main__":
    139. import sys
    140. app = QtWidgets.QApplication(sys.argv)
    141. MainWindow = QtWidgets.QMainWindow()
    142. ui = Ui_MainWindow()
    143. ui.setupUi(MainWindow)
    144. MainWindow.show()
    145. q = 1
    146. ui.comboBox.currentTextChanged.connect(ui.comboxshow_text)
    147. ui.pushButton.clicked.connect(lambda:ui.compute(3,q))#链接调用有参数的函数需要lambda 按钮是解决时空问题的关键 默认值需要搭配 全局变量
    148. sys.exit(app.exec_())

  • 相关阅读:
    java中锁的面试题
    vuex 中使用了modules,如何在页面中调用actions里面的方法
    汉语拼音标注
    qtdesigner使用QTableWidget控件实现读取excel表
    OpenCL编程指南-11.1OpenCL嵌入式简档
    玩转C语言:深入理解输入输出函数的奥秘
    从书本《皮囊》摘录的几个句子
    ShopXO商城系统文件上传0Day代审历程
    6.网络-基础
    C#求100-999之间的水仙花数,你知道多少个?让我们一起来探索!
  • 原文地址:https://blog.csdn.net/m0_45359314/article/details/126733765