| | |
Server with gui interface
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2009
Posts: 56
Reputation:
Solved Threads: 6
Hey guys, I got a little bored and thought I would to make some of the basic Client/Server applications I have a little bit flashier with a gui interface. So far I have just been working with the server and the main problem that I run into is when the program has to enter a loop while waiting for a response the gui starts to hang. The work around I have been using so far which quite frankly sucks, is to print a response while the exeption is being raised. It keeps the gui from hanging but it's quite annoying. The other thing I tried was to have it sleep for a short period of time but the gui seems to really hate that. Is there a more common or better way to handle this? Here is the code I'm working with at the moment, sorry I do relize it's pretty sloppy right now. I promise to clean it up a bit once I can get it functioning a little better
.
. python Syntax (Toggle Plain Text)
from tkinter import * from threading import Thread from time import sleep import socket class Gui(): def __init__(self, master): self.running = 0 #not listening self.addr = "" self.conn = "" self.frame = Frame(master) self.frame.pack(side = LEFT, anchor = N) self.startb = Button(self.frame, text = "Start", command = self.startc) self.startb.pack(side = LEFT, anchor = N) self.stopb = Button(self.frame, text = "Stop", command = self.stopc) self.stopb.pack(side = LEFT, anchor = N) self.connectionl = Label(self.frame, text = "not connected") self.connectionl.pack(side = LEFT, anchor = SW) def startc(self): if self.running == 0: self.running += 1 self.ls = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port = 9999 self.ls.bind(('', port)) print("Server listening on port %s" %port) self.ls.listen(1) self.ls.settimeout(.05) while self.running != 0: try: (self.conn, self.addr) = self.ls.accept() print("client is at", self.addr[0], "on port", self.addr[1]) self.running = 0 except: print("attempting to connect")#hangs without this if self.conn != "": self.rc = "" while self.rc != "done": try: self.rc = self.conn.recv(100).decode('utf-8') print("got command", self.rc) except: sleep(.05) print("no info sent yet")#hangs without this self.conn.close() else: self.running = 0 print("Server not listening") def stopc(self): self.running = 0 root = Tk() gui = Gui(root) root.mainloop()
0
#2 Nov 1st, 2009
Don't know on TkIntering,
but if you're serious with your app, grab wxPython and MySQL-python. Make a client that will access remotely the mysql server, authenticate it and populate data/delete depending on whether they are admins or not
After that exercise, you will be fresh for a rest
but if you're serious with your app, grab wxPython and MySQL-python. Make a client that will access remotely the mysql server, authenticate it and populate data/delete depending on whether they are admins or not
After that exercise, you will be fresh for a rest
![]() |
Other Threads in the Python Forum
- Previous Thread: Unclear control flow variables?
- Next Thread: Tic Tac Toe
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti approximation array assignment backend basic beginner binary bluetooth builtin calculator character chmod code converter countpasswordentry curved customdialog dan08 dictionaries dictionary drive dynamic examples excel exe file float format ftp function gnu graphics gui heads homework import input java launcher line linux list lists loop mouse mysqlquery number numbers output parsing path plugin pointer port prime program programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive refresh scrolledtext ssh stamp statistics string strings sum table terminal text textarea thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows write wxpython xlib






