Skip to content

Instantly share code, notes, and snippets.

Created Jun 10, 2012
Embed
What would you like to do?
gui.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtNetwork import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
@pyqtSlot()
def sendAndRecive(self):
textToSend = QByteArray();
textToSend.append(self.textSend.text());
self.socket.writeData(textToSend);
self.socket.flush()
print(self.socket.bytesAvailable())
def initUI(self):
self.setFixedSize(250, 150);
self.move(100, 100);
self.setWindowTitle('Client')
btnSend = QPushButton('Send')
btnExit = QPushButton('Exit')
self.textSend = QLineEdit();
self.textRecive = QLineEdit();
self.textRecive.setReadOnly(True);
mainLayout = QGridLayout();
self.setLayout(mainLayout);
mainLayout.addWidget(self.textRecive, 0, 0, 1, 0);
mainLayout.addWidget(self.textSend, 1, 0);
mainLayout.addWidget(btnSend, 1, 1);
mainLayout.addWidget(btnExit, 2, 0, 1, 0);
mainLayout.setSpacing(0);
self.show()
self.connect(btnExit, SIGNAL("clicked()"), qApp, SLOT("quit()") )
self.connect(btnSend, SIGNAL("clicked()"), self, SLOT("sendAndRecive()") )
self.socket = QTcpSocket();
self.socket.connectToHost("localhost", 8080);
def main():
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment