473,395 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Server app freezes with Tkinter GUI

2
This is my server script when running it without GUI the start method only it works fine but when running the whole script and I press the start button it just freezes and not responding and nothing appears on the text window



Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. import socket
  4. import sys
  5.  
  6. class Application(Frame):
  7.  
  8.     def __init__(self, master):
  9.  
  10.         Frame.__init__(self, master)
  11.         self.grid()
  12.         self.create_widgets()
  13.  
  14.     def create_widgets(self):
  15.  
  16.         self.text = Text(self, width = 35, height = 5, wrap = WORD)
  17.         self.text.grid(row = 0, column = 0, columnspan = 2, sticky = W)
  18.  
  19.         self.submit_button = Button(self, text='start', command = self.start)
  20.         self.submit_button.grid(row = 2, column = 0, sticky = W)
  21.  
  22.     def start(self):
  23.  
  24.         self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  25.         self.text.insert(0.0, 'Server started!\n' )
  26.         self.s.bind(('',1090))
  27.         self.s.listen(10)
  28.         sc, address = self.s.accept()
  29.         self.text.insert(0.0, 'Got conn from', address )
  30.         while True:
  31.  
  32.             '''msg = sc.recv(1024)
  33.             print address, ' >> ', msg
  34.             msg = raw_input('SERVER >> ')
  35.             sc.send(msg)'''
  36.             i=1
  37.             f = open('file_'+ str(i)+".txt",'wb') #open in binary
  38.             i=i+1
  39.             while (True):       
  40.                 l = sc.recv(1024)
  41.                 while (l):
  42.                     print l 
  43.                     f.write(l) 
  44.                     f.flush()
  45.                     l = sc.recv(1024)
  46.             f.close()
  47.  
  48.             sc.close()
  49.  
  50.         #s.close()
  51.  
  52.  
  53. root = Tk()
  54. root.title("Server")
  55. root.geometry("500x250")
  56. app = Application(root)
  57.  
  58. root.mainloop()
Apr 23 '13 #1
3 3077
dwblas
626 Expert 512MB
Add a print statement at the beginning of start() and another after the socket statement to see if that is the hang-up, as the Tkinter code appears to work ok. Note that the inner "while True" statement never exits so the outher while True will only execute once.
Apr 24 '13 #2
dwblas
626 Expert 512MB
It appears that Tkinter requires an update_idletasks() because of all of the other processing going on.
Expand|Select|Wrap|Line Numbers
  1.          self.text.insert(0.0, 'Server started!\n' )
  2.          self.text.update_idletasks()
  3.  
  4.          self.text.insert(0.0, 'Got conn from', address )
  5.          self.text.update_idletasks() 
The hang-up now appears to be this line
Expand|Select|Wrap|Line Numbers
  1.          sc, address = self.s.accept()
Apr 24 '13 #3
shaf3e
2
i am new to socket programming ana i saw that the problem with accepting the connection but it was working well before buiding the GUI i dont know what to do
Apr 25 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
1
by: Noah | last post by:
I have a long running application with a Tkinter GUI. Is there a way to see how many events are pending in the queue? I want my application to occasionally process events (so that the output...
3
by: Bob Greschke | last post by:
I have a program where the user pushes a button, a "starting" message is ..inserted to a text field with an associated scroll bar, a thread is started that inserts a "working..." message on to the...
1
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker...
2
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...
1
by: srihari | last post by:
Hai, I am trying to install IBM DB2 8.1 on Red Hat linux 8.0. My machine is Intel XEON 64bit. The installation went well except for the creation of tools catalog. When I tried to install the tools...
0
by: Marcin Szarek | last post by:
Hi! For a few months we suffer mysterious problem with Oracle 10g RAC (more details on server configuration at the bottom). At regular basis (every 5 minutes) nodes of our cluster "freeze" -...
3
by: vedran_dekovic | last post by:
Hi, I need help about Tkinter listbox widget.I want,when somebody click on any item(file) in Listbox,then in new Label widget text must be selected item from server. my program (wrong...
32
by: Kevin Walzer | last post by:
I'm a Tcl/Tk developer who has been working, slowly, at learning Python, in part because Python has better support for certain kinds of applications that I want to develop than Tcl/Tk does....
44
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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,...
0
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...

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.