473,414 Members | 1,698 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,414 software developers and data experts.

tkinter + interrupts

hi!

on my gui, i have a "start server" button and a "stop server" button.
the problem is "start server" will loop infinitely and respond to requests.
i'd like to be able to click on "stop server" and get the server to stop.

how would i go about doing it? i can think of a soln involving threads,
where i have "start server" in a separate thread and have it continously
poll a shared variable. but is there another solution not involving
threads.

thanks

cheers

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
1 5784
Ajay wrote:
hi!

on my gui, i have a "start server" button and a "stop server" button.
the problem is "start server" will loop infinitely and respond to requests.
i'd like to be able to click on "stop server" and get the server to stop.

how would i go about doing it? i can think of a soln involving threads,
where i have "start server" in a separate thread and have it continously
poll a shared variable. but is there another solution not involving
threads.


It's possible, but it may be a bit weird. All you have to do is return the
control back to the Tkinter mainloop at regular intervals via the update method
so that the GUI remains active. Here is an example:

--------------------------------------------------------
import time
from Tkinter import *

root = Tk()

lbl = Label(root, text='Blink')
lbl.pack(side=TOP)

doLoop = 1

def start():
x = 0
while doLoop:
if x:
lbl.configure(fg='red')
else:
lbl.configure(fg='black')
x = not x
time.sleep(1)
root.update()

def stop():
global doLoop
doLoop = 0

Button(root, text='Start', command=start).pack(side=LEFT)
Button(root, text='Stop', command=stop).pack(side=LEFT)

root.mainloop()
--------------------------------------------------------

This is a bit weird, since the GUI is not *always* active; it is only once every
second. So clicking the 'Stop' button may have a one second delay before being
taken into account.

Also remember that the example above is very simple: in real life, you may not
have the occasion to call the update method regularly enough. So a solution
involving threads is sometimes hard to avoid...

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #2

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

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
3
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
4
by: jmarcrum | last post by:
I have to modify this assembly code in order to make it use interrupts. Right now, when I push button 1 on the microprocessor the count increments once (the LED's count in binary, using only 3 LED's...
1
by: JKaur | last post by:
hello frnds, please tell me the difference between DOS interrupts and interrupts invoked using int86() function in C (are those 8086 intrupts?). In some text i have read these are different, but...
8
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
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:
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...

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.