The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
Re: GUI lockup
[Originally posted by daryl harms]

Hi Al,

It is Ken who wrote the Tkinter chapter and is the expert on it. However,
there are a couple of things I can think of that might be your problem.

The first is if you are running this from within the IDLE editor you should
comment out the last line, i.e. #root.mainloop(). Since IDLE is already
running a Tkinter event loop this can cause lock up.

The other is you might want to try:
QuitBut = Button(root, text='Quit', command=root.destroy)

rather than:
QuitBut = Button(root, text='Quit', command=root.quit)

in the third last line as I would guess that is the functionality you are
probably really after here.

Daryl
import-bot (20211) [Avatar] Offline
#2
Re: GUI lockup
[Originally posted by daryl harms]

Hi Al,

I can see from a second look at your example that I didn't answer your real
question at all.

I'm not up on Tkinter so can't give you details. Only can give you a couple of
pointers to things that might help in this.

The first is you can instead of calling root.mainloop(), create your own loop
in which you make a call to root.update_idletasks() interspersed with your own
function calls.

The second is I believe you can use something like the after() method in the
Misc class to asynchronously have a function get fired off in the future
within the TK event loop.


For more details you might want to ask this question on John Grayson's forum
for his book, as he definitely has much more expertise on this than me.


Daryl
import-bot (20211) [Avatar] Offline
#3
[Originally posted by al123]

Hello,

I've been trying for some time now to figure out how to have a function run
without freezing the Tkinter GUI. Please point me in the right direction as to
what I can do with this. Thanks for your time, Al

from Tkinter import *
from time import *

root = Tk()
root.title('Top Level')
UserEntry = IntVar()

EntryBox = Entry(root, state=NORMAL, textvariable=UserEntry, width=10)
EntryBox.pack()
var = UserEntry.get()

Hour_Min=localtime(time())
ClockMin=Hour_Min[4]
ClockHour=Hour_Min[3]
InputMin=var
InputHour=Hour_Min[3]


def ActionButCmd():
global InputMin, InputHour, var
var = UserEntry.get()
Hour_Min=localtime(time())
ClockMin=Hour_Min[4]
ClockHour=Hour_Min[3]
InputMin=var
InputHour=Hour_Min[3]
if ClockMin<InputMin:>
while ClockMin<InputMin: >
sleep(5)
Hour_Min=localtime(time())
ClockMin=Hour_Min[4]
ClockHour=Hour_Min[3]
print "Great"
if ClockMin>=InputMin:
print "END"

ActionBut = Button(root, text='Action', command=ActionButCmd)
ActionBut.pack(side=RIGHT)
QuitBut = Button(root, text='Quit', command=root.quit)
QuitBut.pack(side=LEFT)
root.mainloop()
import-bot (20211) [Avatar] Offline
#4
Re: GUI lockup
[Originally posted by al123]


Thanks for your advise in resolving this problem. I've some programming
experiance with VB for applicaions, but this is my first attempt at broad
spectrum programming. I'll reseach the methods you suggested and would
appreciate a little more elaboration on the root.update_idletasks()
suggestion, if you don't mind.

Thanks again, Al
import-bot (20211) [Avatar] Offline
#5
Re: GUI lockup
[Originally posted by daryl harms]

>
> Thanks for your advise in resolving this problem. I've some programming
> experiance with VB for applicaions, but this is my first attempt at broad
> spectrum programming. I'll reseach the methods you suggested and would
> appreciate a little more elaboration on the root.update_idletasks()
> suggestion, if you don't mind.
>
> Thanks again, Al

Hi Al,


There are short descriptions of the event processing calls (including
"update_idletasks" and "update") in Fredrik Lundh's online document at:

http://www.pythonware.com/library/tkinter/introduction/x8996-event-processing.htm


However, I'm not sure I'm steering you right with that suggestion. A cleaner
option depending on what you are ultimately trying to do, might instead be
starting a separate thread for your asynchronous task.

You can find some ideas and sample code on using threads within Tkinter in the
following two messages:

http://www.python.org/pipermail/python-list/2000-August/114803.html
http://www.python.org/pipermail/python-list/2000-July/108590.html

Hope that helps some. As I said this is an area I can't claim expertise in.

Daryl