小编fah*_*aus的帖子

属性错误:对象在python中没有属性

我有以下类 Ui_MainWindow(object)。但是我得到了属性错误,即AttributeError: 'Ui_MainWindow' object has no attribute 'ser' .ser 在 check_phone() 方法中的 definet 之前。问题出现在 sendMessage() 方法中。为什么 .ser 不再被识别?

    from PyQt5 import QtCore, QtGui, QtWidgets

    import Tkinter as tk
    import tkFileDialog as filedialog
    import tkMessageBox
    import serial
    import time

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(503, 486)
        self.pushButton_2 = QtWidgets.QPushButton(self.widget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.gridLayout.addWidget(self.pushButton_2, 3, 2, 1, 1)
        self.pushButton_2.clicked.connect(self.send_sms) #send sms function

    def check_phone(self):
         ser = serial.Serial('/dev/ttyACM0', 
                 460800, 
                 timeout=5, 
                 xonxoff = False,   
                 rtscts = False, 
                 bytesize = serial.EIGHTBITS, 
                 parity = serial.PARITY_NONE, 
                 stopbits …
Run Code Online (Sandbox Code Playgroud)

python attributes object

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

attributes ×1

object ×1

python ×1