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 !