Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:38:14+00:00 2026-06-05T23:38:14+00:00

When using the select.select() method in Python, is there any way to use input

  • 0

When using the select.select() method in Python, is there any way to use input from a GUI (Tkinter Entry) to send data out of a socket?

The input list of select() accepts sys.stdin or received data from a server, but is there anyway to get data from a GUI and have it be sent out? Or is select not usable with a GUI?

I have searched extensively, but if you have a link to another thread I’d appreciate that as well.

import socket, select, threading, Queue, cPickle
from Tkinter import *
from Message import *

class GUI(Frame):

    def __init__(self, host="localhost",port=5678, root="Tk()"):
        Frame.__init__(self,root)
        self.nickname = raw_input("What is your screen name? ")
        self.inqueue = Queue.Queue()
        self.outqueue = Queue.Queue()
        self.root = root
        self.text = Text(self,height=10,width=40)
        self.scroll=Scrollbar(self)
        self.text.configure(yscrollcommand=self.scroll.set)
        self.scroll.grid(row=0, column=1, sticky=N+S)
        self.scroll.config(command=self.text.yview)
        self.text.grid(row=0,column=0)
        self.entry = Entry(self)
        self.entry.grid(row=1,column=0)
        self.pack()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((host, port))
        self.sock.send(self.nickname)
        self.thread1=threading.Thread(target=self.cmdloop)
        self.thread1.start()
        self.entry.bind("<Return>",self.enter)
        self.call()

    def enter(self,event):
        msg = Message(self.nickname,0,self.entry.get())
        self.entry.delete(0, END)
        msg = cPickle.dumps(msg)
        self.inqueue.put(msg)
        self.sock.send(msg)

    def call(self):
        self.processData()
        self.after(100,self.call)

    def cmdloop(self):
        while 1:
            sys.stdout.flush()
            # Wait for input from stdin & socket
            inputs, outputs, excepts = select.select([0,self.sock],[],[])

            for i in inputs:
                if i == 0:
                    data = sys.stdin.readline()
                    msg = Message(self.nickname,0,data)
                    msg = cPickle.dumps(msg)
                    self.inqueue.put(msg)
                    self.sock.send(msg)

                elif i == self.sock:
                    data = self.sock.recv(1024)
                    self.inqueue.put(data)

    def processData(self):
        while self.inqueue.qsize():
            try:
                msg = self.inqueue.get(0)
                msg = cPickle.loads(msg) 
                self.text.insert(END, msg.getusr()+": "+msg.getmsg())
                self.text.yview(END)
            except Queue.Empty:
                pass

if __name__ == "__main__":
    root = Tk()
    root.title("textarea")
    client = GUI(sys.argv[1],int(sys.argv[2]),root)
    root.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:38:15+00:00Added an answer on June 5, 2026 at 11:38 pm

    I think I was asking the question poorly, thank you to those who tried to answer despite my poor phrasing. I had just started using Python. Either way, here is an answer my group member found to the question I was trying to ask. I do not know if he wrote it himself or found it on a website, but it is basically just a use of the TKinter after() call.

    Our main loop looks like:

    def cmdloop():
        (sread, swrite, sexc) = select.select( [sock], [], [], 0)
        for s in sread:
            ...
            ...
            ...
        app.after(500,cmdloop)
    

    That half second break allowed the textbox call inputBox.bind('<Return>', sendMsg) (and the message waiting to send in the socket) to work properly. sendMsg() then simply had a sock.send() call.

    def sendMsg(event=''):
        message = inputBox.get()
        message += "\n"
        msg = Message(nickname,0,message,None) #Custom Class
        sock.send(pickle.dumps(msg))
        inputBox.delete(0,END)
        return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a GUI in Python using the Tkinter module, and part
I am using the .eq() method to select a specific child element of a
I was using the Add class method $(select[name=' + ABC+ i + ']).addClass('addBorder'); This
I am working on select box and using jquery. HTML structure: <form method= action=
There is a drop down using select <%= select(array, folder, @rows.keys, {}, :onchange =>?
Just a quick question about using select() . I'm using select() to read from
My Java NIO Selector is implemented using select() so it blocks until any of
I have been using the scipy.stats.invgamma.rvs function to randomly select values from an inverse
I am trying to get information from an SQL database using python I was
I'm using flask as a python framework with sqlalchemy. The models use the query_property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.