473,804 Members | 3,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tkinter socket client ?

I have been looking through the previous posts - but with my lack of
knowledge on the whole tkinter subject - I have no clue what to look
for ...

SO - can anyone please help with this ...?

I have a python server that when it gets a connection from a client -
it sends data back - quite a bit of it - in discreet parts - around
1024 byte chunks ...

I have created a tkinter client that makes a simple connect to the
server. What I have a problem with is I need the client to write all
the data to the Text() widget created in the GUI client - the Text()
widget is created as :

self.text=Text( self.center_fra me,background=' white')
scroll=Scrollba r(self.center_f rame)
self.text.confi gure(yscrollcom mand=scroll.set )

self.text.pack( side=LEFT, fill=BOTH, expand=YES)
scroll.pack(sid e=RIGHT,fill=Y)
self.center_fra me.pack(side=RI GHT, expand=YES, fill=BOTH)
I have a button with "Connect" written on it that connects to the
server by calling :

HOST = 'localhost'
PORT = 9000
global s
for res in socket.getaddri nfo(HOST, PORT, socket.AF_UNSPE C,
socket.SOCK_STR EAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(a f, socktype, proto)
except socket.error, msg:
s = None
continue
try:
s.connect(sa)
except socket.error, msg:
s.close()
s = None
continue
break
if s is None:
print 'could not open socket'
self.quitButton Click

NOW - HOW do I get the server's sent data to continuiosly print in the
Text() widget ?

Many thank
Tonino

Jul 18 '05 #1
12 6171
On 20 Jan 2005 22:25:52 -0800, rumours say that "Tonino"
<to**********@g mail.com> might have written:

[tkinter gui for a socket client, lots of data from the socket]
NOW - HOW do I get the server's sent data to continuiosly print in the
Text() widget ?


You need to use:

yourTextWidget. insert(Tkinter. END, data) # to insert the data
yourRootWindow. update_idletask s() # to update the GUI
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #2
thanks for the reply .

just one problem - I do not know how to sit in a "loop" accepting
messages on the socket connection - writting them to the Text() widget
- refreshing the the GUI - and then starting all over ....
where do I put the loop for the socket ?

Thanks
Tonino

Jul 18 '05 #3
> just one problem - I do not know how to sit in a "loop" accepting
messages on the socket connection - writting them to the Text() widget
- refreshing the the GUI - and then starting all over ....
where do I put the loop for the socket ?


Another thread? Or use twisted, it comes with a tkinter-aware exec-loop:

http://twistedmatrix.com/documents/h...eactor#auto16:

--
Regards,

Diez B. Roggisch
Jul 18 '05 #4
thanks for the info - but I really do not want to learn twisted before
I can understand Tkinter ;)
another thread seems the way - will try that ...

Thanks
Tonino

Jul 18 '05 #5
You are probably looking for Tkinter.createf ilehandler(). Here are
some snippets to get you started:

tk_reactor = Tkinter._tkinte r
self.sd = socket(AF_INET, SOCK_STREAM)
self.sd.connect ((HOST, PORT))
tk_reactor.crea tefilehandler(s elf.sd, Tkinter.READABL E,
self.handle_inp ut)

def handle_input(se lf, sd, mask):
data = self.sd.recv(SI ZE)
(Sorry if the formatting is busted, blame google groups.)

HTH,
Neal

Jul 18 '05 #6
hi there ,

yeah - had a look at createfilehandl er() - was a bit confusing - but
your example helps ;)

Thanks
Tonino

Jul 18 '05 #7
In article <11************ **********@c13g 2000cwb.googleg roups.com>,
"Tonino" <to**********@g mail.com> wrote:
yeah - had a look at createfilehandl er() - was a bit confusing - but
your example helps ;)


Be warned that createfilehandl er does not work on Windows, though it
works well on unix and MacOS X.

So my suggestion is one to try any of these (any of which are preferable
to threads):
- file handlers for non-Windows code
- use tcl sockets for cross-platform code.
- use Twisted Framework (some work to learn, but supposedly very solid;
I confess I've never used it myself).

There is a bit of info on the first two options (including a link to the
RO package that includes a python interface to tcl sockets) here:

<http://www.astro.washi ngton.edu/rowen/TkinterSummary. html#FileHandle rs>

-- Russell
Jul 18 '05 #8
Hi,

thanks for this info - I had to abandon the createfilehandl er() method
as it is not supported in windows and the GUI "might" be used there at
some time ...

So - I went the threading route - works well - for now - so I will
stick to it ...

BUT - the next question:
In the Text() widget - why - when the text scrolls off the screen -
does the window not follow it ?

I have added a scrollbar to it :

self.center_fra me = Frame(self.top_ frame, background="tan ",
relief=RIDGE)

self.text=Text( self.center_fra me,background=' white')
scroll=Scrollba r(self.center_f rame)
self.text.confi gure(yscrollcom mand=scroll.set )

self.text.pack( side=LEFT, fill=BOTH, expand=YES)
scroll.pack(sid e=RIGHT,fill=Y)
self.center_fra me.pack(side=RI GHT, expand=YES, fill=BOTH)
but the window does not scroll to follow the text ?
Any ideas ?

Thanks
Tonino

Jul 18 '05 #9
Tonino wrote:
Hi,

thanks for this info - I had to abandon the createfilehandl er() method
as it is not supported in windows and the GUI "might" be used there at
some time ...

So - I went the threading route - works well - for now - so I will
stick to it ...

BUT - the next question:
In the Text() widget - why - when the text scrolls off the screen -
does the window not follow it ?

I have added a scrollbar to it :

self.center_fra me = Frame(self.top_ frame, background="tan ",
relief=RIDGE)

self.text=Text( self.center_fra me,background=' white')
scroll=Scrollba r(self.center_f rame)
self.text.confi gure(yscrollcom mand=scroll.set )

self.text.pack( side=LEFT, fill=BOTH, expand=YES)
scroll.pack(sid e=RIGHT,fill=Y)
self.center_fra me.pack(side=RI GHT, expand=YES, fill=BOTH)
but the window does not scroll to follow the text ?
Any ideas ?


This is the default behavior of the Text widget. You have two options
(as I see it) one, put the new text at the top of the Text widget
textwidget.inse rt(0, "your new text") or two, use the yview_pickplace
method to move the view down every time you insert text
textwidget.yvie w_pickplace('en d')

I wrote a sub-class of the ScrolledText widget to do just this
I gave it a write method - so I could re-direct stdout to it - and also
called yview_pickplace in that method.

HTH
Martin.

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2255
by: Thomas Buschhardt | last post by:
Hallo, I have a problem with Tkinter and the module socket. In a console-window everything works fine, but in a Tkinter-window I can no more use the widgets. I found some other mails with this problem, but no solution (I understand really :-) Here is my code: ----------------------------------------------- import win32ui, dde, string, time, os, sys, shutil
5
3851
by: george.trojan | last post by:
My application consists of Tkinter GUI that has to communicate with a remote server. The communication is bi-directional: the GUI responds to remote requests and user actions uch as pressing a button) should send messages to the server. I want to have the network interface implemented as a separate thread, as it may take a while to proccess incoming messages. My initial approach is the following
0
1921
by: Rod Stephenson | last post by:
I am developing an engineering application for modelling multiphase flows in large pipe networks, and have just discovered the joy of pyopengl for 3D visualization. However the incantation I'm using - with glut on Windows - doesnt coexist well with other python gui's - glutMainLoop() appears not to work alongside tkinter.mainloop(). (I tried putting them in separate threads but no success there either) The issue has been raised in various...
2
4403
by: Michael Zhang | last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images from server and display those images. I created a thread (also a separate toplevel window) for displaying images and another thread for recording the frame rates (using a progress bar for visulization). The whole application worked very well once it received image data from the socket. The problem is when I tried to close that display window (click on the standard...
2
2957
by: Tonino | last post by:
Hi, I have a small Tkinter app that gets data from a socket connection to a "server". The app has a Text() widget to display the info that it gets from the socket connection. I have the ability to stop the text at any point. What I want to be able todo is select a line from the Text() window and double click or whatever on it to open a new window with that selected text as a paramater to the new window.
4
8742
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects the child socket remains in the CLOSE_WAIT state. Anyone have any idea what's missing? ----------------------------- Socket Code ----------------------------- namespace Sockets { #region Class - SocketClient
2
2881
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job is to make a server, none of us know nothing about socket programming in C#, but we founds some guides for this, and now ,got a server running, but we have some problems though. We have 2 scenario, one where we use a telnet connection and one...
44
5012
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
1
7200
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN site, which is actually for sending strings. I tried to adapt this code so that the client sends an image instead of a string. However, there is something wrong on the server side (i guess)... The server starts listening, the client starts sending...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.