qq_43412960
2019-11-30 15:46
采纳率: 50%
浏览 330
已采纳

这是一个关于 PYTHON 的PYQT5的相关问题

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(340, 430, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(510, 430, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(280, 200, 411, 161))
        self.textEdit.setObjectName("textEdit")
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(210, 90, 113, 20))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(410, 90, 113, 20))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(80, 90, 54, 12))
        self.label.setObjectName("label")
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(600, 100, 75, 23))
        self.pushButton_3.setObjectName("pushButton_3")
        self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_3.setGeometry(QtCore.QRect(190, 430, 113, 20))
        self.lineEdit_3.setObjectName("lineEdit_3")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "发送"))
        self.pushButton_2.setText(_translate("MainWindow", "关闭"))
        self.label.setText(_translate("MainWindow", "服务器"))
        self.pushButton_3.setText(_translate("MainWindow", "连接"))
import sys
from PyQt5 import QtWidgets
import untitled
import   socket
class Mywindow(QtWidgets.QMainWindow, untitled.Ui_MainWindow):
    quest=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    def __init__(self):
        super(Mywindow, self).__init__()
        self.setupUi(self)  #继承于Ui_MainWindow
        self.pushButton_3.clicked.connect(self.lianjie)
        self.pushButton.clicked.connect(self.xiaoxi)
    def  lianjie(self):
        self.quest.connect((self.lineEdit.Text(),int(self.lineEdit_2.Text())))
    def  xiaoxi(self):
        self.quest.send(self.lineEdit_3.Text().encode())
        a=self.quest.recv(100).decode()
        self.textEdit.setText(a)
        self.quest.close()
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = Mywindow()
    window.show()
    sys.exit(app.exec_())

上面是客户机代码 ,代码和PYQT5联系在一起了

下面是服务器代码,没有和窗体联系在一起

import   socket
service=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
service.bind(('127.0.0.1',6))
service.listen(3)
tao,add=service.accept()
data=tao.recv(100).decode()
tao.send(data.encode())
tao.close()
service.close()

为什么我打开客户机,连接按钮 ,系统退出,产生错误呢?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题