"Chris Lee" <[email protected]> wrote

Before I tell you about my problems, I ask for your consideration
as I am a newbie at python...

That's OK, its what the tutor list is for! :-)

I was having problems as I tried to open another program
within a program (both programs are Tkinter UIs)

OK, That can be tricky, especially if you want the two programs
to communicate but it is possible.

def showtime():
    os.system("clock.py")

window = Tk()
frame = Frame(window)
frame.pack()

clock_command = lambda : showtime()
b3 = Button(frame, text="What time is it?", command=clock_command)

Why not miss out the lambda and just do:

b3 = Button(frame, text="What time is it?", command=showtime)

lambdas are there to save you creating names for small one-liner type programs. In you case the onle liner just calls another function to you might as well just
use the function directly as your command.

b3.pack()
window.mainloop()

And the following code is the clock.py:
------------------------
#program: clock.py
import Tkinter
import time

currenttime = ''
clock = Tkinter.Label()
clock.pack()

def tick():
   global currenttime
   newtime = time.strftime('%H:%M:%S')
   if newtime != currenttime:
       currenttime = newtime
       clock.config(text=currenttime)
   clock.after(200, tick)

tick()
clock.mainloop()
-----------------------

I know for certain that the "clock.py" works (because i got it from the web.. -_-;;)

And you ran it from a command prompt and it worked ok?

Its a very unusual Tkinter program in that it doesn't have any of
the usual Tkinter preamble...

but I'm having a real difficulty trying to open clock.py through my real program....

That might be bbecause you are calling clock.py directly instead of
invoking the interpreter. That may depend on the Operating system
you are using however...

Can you tell us what does happen?


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to