[Tutor] Newbie question on passing a variable

Remco Gerlich scarblac@pino.selwerd.nl
Sun, 20 Aug 2000 21:20:12 +0200


On Sun, Aug 20, 2000 at 02:10:46PM -0400, FxItAL@aol.com wrote:
> Hello All,
> 
> I've written the following to try and get input from the user. This works fine, my problem is passing it the variable InputMin in the other module - timer1.py.
> 
> from Tkinter import *
> 
> root = Tk()                                             
> root.title('Top Level')                                 
> 
> e = StringVar()
> global e

This isn't necessary, you don't declare it inside something, it's already
global in the module.

> d = Entry(root, textvariable=e, width=10)
> d.pack()                                                
> var = e.get()
> 
> def z():
>     var =  e.get()  
>     import timer1
>     timer1.TimeFunc(var)
> f = Button(root, text='Print',command=z)
> f.pack(side=RIGHT)        
> 
> root.mainloop()

Try to think of some better variable names. I'm already getting confused a
bit about d, var, e, z and f :).

var is a string. if you want to use it as an int, use something like
'var = int(e.get())'.

> 
> Thie timer1.py module:
> 
> def TimeFunc(var):
> from time import *  
>     me = time()
>     you=localtime(me)
>     ClockMin=you[4] #Represents Minute on Clock
>     ClockHour=you[3] #Represents Hour on Clock
>     InputMin=var
>     InputHour=you[3]
>     if ClockMin<InputMin:

Here you're comparing an integer (ClockMin) with a string (var). That
give some result, but not a useful result. Try to use int() on it.

>         while ClockMin<InputMin or ClockHour<InputHour:             me = time()
>             you=localtime(me)                                       ClockMin=you[4]
>             ClockHour=you[3]
>         print "great"
> 
> If I use only these two lines:
> 
> def TimeFunc(var):
>     print var
> 
> it works.
> 
> I know this is alot to ask but any help will be greatly appreciated.

Well, I can't test it out here, and you don't say what goes wrong, but
that could be it.

It seems that the function of the while loop is to wait until some minutes
have past; you should use time.sleep() for that (it waits for a number of
seconds).
-- 
Remco Gerlich,  scarblac@pino.selwerd.nl