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_frame,background='white ')
scroll=Scrollbar(self.center_frame)
self.text.configure(yscrollcommand=scroll.set)
self.text.pack(side=LEFT, fill=BOTH, expand=YES)
scroll.pack(side=RIGHT,fill=Y)
self.center_frame.pack(side=RIGHT, 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.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, 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.quitButtonClick
NOW - HOW do I get the server's sent data to continuiosly print in the
Text() widget ?
Many thank
Tonino 12 6114
On 20 Jan 2005 22:25:52 -0800, rumours say that "Tonino"
<to**********@gmail.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_idletasks() # 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...
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
> 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
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
You are probably looking for Tkinter.createfilehandler(). Here are
some snippets to get you started:
tk_reactor = Tkinter._tkinter
self.sd = socket(AF_INET, SOCK_STREAM)
self.sd.connect((HOST, PORT))
tk_reactor.createfilehandler(self.sd, Tkinter.READABLE,
self.handle_input)
def handle_input(self, sd, mask):
data = self.sd.recv(SIZE)
(Sorry if the formatting is busted, blame google groups.)
HTH,
Neal
hi there ,
yeah - had a look at createfilehandler() - was a bit confusing - but
your example helps ;)
Thanks
Tonino
In article <11**********************@c13g2000cwb.googlegroups .com>,
"Tonino" <to**********@gmail.com> wrote: yeah - had a look at createfilehandler() - was a bit confusing - but your example helps ;)
Be warned that createfilehandler 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.washington.edu/rowen/TkinterSummary.html#FileHandlers>
-- Russell
Hi,
thanks for this info - I had to abandon the createfilehandler() 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_frame = Frame(self.top_frame, background="tan",
relief=RIDGE)
self.text=Text(self.center_frame,background='white ')
scroll=Scrollbar(self.center_frame)
self.text.configure(yscrollcommand=scroll.set)
self.text.pack(side=LEFT, fill=BOTH, expand=YES)
scroll.pack(side=RIGHT,fill=Y)
self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
but the window does not scroll to follow the text ?
Any ideas ?
Thanks
Tonino
Tonino wrote: Hi,
thanks for this info - I had to abandon the createfilehandler() 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_frame = Frame(self.top_frame, background="tan", relief=RIDGE)
self.text=Text(self.center_frame,background='white ') scroll=Scrollbar(self.center_frame) self.text.configure(yscrollcommand=scroll.set)
self.text.pack(side=LEFT, fill=BOTH, expand=YES) scroll.pack(side=RIGHT,fill=Y) self.center_frame.pack(side=RIGHT, 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.insert(0, "your new text") or two, use the yview_pickplace
method to move the view down every time you insert text
textwidget.yview_pickplace('end')
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.
In article <11**********************@z14g2000cwz.googlegroups .com>,
"Tonino" <to**********@gmail.com> wrote: thanks for this info - I had to abandon the createfilehandler() 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_frame = Frame(self.top_frame, background="tan", relief=RIDGE)
self.text=Text(self.center_frame,background='whit e') scroll=Scrollbar(self.center_frame) self.text.configure(yscrollcommand=scroll.set)
self.text.pack(side=LEFT, fill=BOTH, expand=YES) scroll.pack(side=RIGHT,fill=Y) self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
but the window does not scroll to follow the text ? Any ideas ?
That's just how it works. But when you append text you can easily tell
the text widget to display it, e.g. using "see". Here is the code I use
(from RO.Wdg.LogWdg.py), which has these useful features:
- auto-scrolls only if the user is already scrolled to the of text (so
if a user is staring at some older data, it won't be jerked out from
under them)
- deletes excess text.
def addOutput(self, astr, category=None):
"""Add a line of data to the log.
Inputs:
- astr: the string to append. If you want a newline, specify the \n
yourself.
- category: name of category or None if no category
"""
# set auto-scroll flag true if scrollbar is at end
# there are two cases that indicate auto-scrolling is wanted:
# scrollPos[1] = 1.0: scrolled to end
# scrollPos[1] = scrollPos[0]: window has not yet been painted
scrollPos = self.yscroll.get()
doAutoScroll = scrollPos[1] == 1.0 or scrollPos[0] == scrollPos[1]
if category:
self.text.insert("end", astr, (category,))
else:
self.text.insert("end", astr)
extraLines = int(float(self.text.index("end")) - self.maxLineIndex)
if extraLines > 0:
self.text.delete("1.0", str(extraLines) + ".0")
if doAutoScroll:
self.text.see("end")
-- Russell
On Tue, 25 Jan 2005 13:44:32 +0000
Martin Franklin <mf********@gatwick.westerngeco.slb.com> wrote: thanks for this info - I had to abandon the createfilehandler() method as it is not supported in windows and the GUI "might" be used there at some time ...
Take a look here: http://www.pythonbrasil.com.br/moin....ketsComTkinter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
| |