hello all
first let me say I am really glad to become a part of this community.

I am college student majoring in computer systems engineering(more hardware than software), but i am really interested in interfacing computers with microcontroller based projects.

I took programming courses in java , and now i am planning to learn python because i think it is exactly what i need because it is simple and has great libraries like pyserial and sockets which are the 2 main libraries that i look for in a programming language.

I am trying to make a python program with GUI interface that would connect to a server socket over LAN, i used code from this forum and it worked great in the command line but when i tried to add the GUI interface it turned into a mess ...
here is my code :
the GUI interface :

from PyQt4 import QtCore, QtGui

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(515, 329)
        self.groupBox = QtGui.QGroupBox(Form)
        self.groupBox.setGeometry(QtCore.QRect(330, 30, 161, 81))
        self.groupBox.setObjectName("groupBox")
        self.lineEdit = QtGui.QLineEdit(self.groupBox)
        self.lineEdit.setGeometry(QtCore.QRect(40, 20, 113, 21))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtGui.QLineEdit(self.groupBox)
        self.lineEdit_2.setGeometry(QtCore.QRect(40, 50, 51, 21))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.pushButton = QtGui.QPushButton(self.groupBox)
        self.pushButton.setGeometry(QtCore.QRect(100, 50, 21, 21))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtGui.QPushButton(self.groupBox)
        self.pushButton_2.setGeometry(QtCore.QRect(130, 50, 21, 21))
        self.pushButton_2.setObjectName("pushButton_2")
        self.label = QtGui.QLabel(self.groupBox)
        self.label.setGeometry(QtCore.QRect(10, 20, 62, 18))
        self.label.setObjectName("label")
        self.label_2 = QtGui.QLabel(self.groupBox)
        self.label_2.setGeometry(QtCore.QRect(10, 50, 62, 18))
        self.label_2.setObjectName("label_2")
        self.textEdit = QtGui.QTextEdit(Form)
        self.textEdit.setGeometry(QtCore.QRect(50, 50, 231, 201))
        self.textEdit.setObjectName("textEdit")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
        QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL('clicked()'),self.con)
        QtCore.QObject.connect(self.pushButton_2,QtCore.SIGNAL('clicked()'),self.disc)
    def con(self):
        return None
    def disc(self):
        return None
    
    def retranslateUi(self, Form):
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.groupBox.setTitle(QtGui.QApplication.translate("Form", "GroupBox", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Form", "C", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("Form", "D", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("Form", "IP:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("Form", "Prt:", None, QtGui.QApplication.UnicodeUTF8))

and my code :

import sys,tcp,socket
from PyQt4 import QtCore, QtGui

class Test(tcp.Ui_Form):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
    def con(self):
        host=self.lineEdit.text()
        port=int(self.lineEdit_2.text())
        self.s.connect((host,port))
        self.s.send("Connected")
        
        
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Test()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())

whenever i push the connect button my frame becomes not responding and it blacks out :D

please help !

I realize that the QT-Designer is tempting to use for a beginner, but the code it spits out is complex and very difficult to troubleshoot. First of all test the module I assume you saved as tcp.py by adding this to the end of the module code ...

# test module
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

thx for the reply
the module works great and the frame appears
the problem occurs when i hit the connect button
the whole program freezes and it doesnt connect to the server socket

My problem seems to be that I cannot enter a port value in self.lineEdit_2.text(). I can't get the cursor there.

press tab after you enter the ip :D

Oh thanks, nothing freezes up since I don't use/know a valid IP. I just get a socket.gaierror.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.