tkinter button disappears after execution of execfile.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shane12345
    New Member
    • Mar 2010
    • 4

    tkinter button disappears after execution of execfile.

    '''on execution of button.py a button appears ,after clicking on the button it calls bounce.py but after closing bounce.py the button also closes...but i want the button to remain open...please help. im posting both the programs button.py and bounce.py NOTE: im using vpython in bounce.py and windows os'''

    button.py
    -------------------------------------------------------------------------------------------------------------------
    Code:
    from Tkinter import *
    import fileinput
    
    root = Tk()
    root.title("Note Taker")
    def Button1():
    	execfile('bounce.py',{})
    
    button1 = Button(root, text="bounce", command = Button1)
    text = Entry(root)
    button1.pack()
    root.mainloop()
    ----------------------------------------------------------------------------------------------------------------
    bounce.py
    -----------------------------------------------------------------------------------------------------------------

    Code:
    from visual import *
    
    floor = box(length=4, height=0.5, width=4, color=color.blue)
    
    ball = sphere(pos=(0,4,0), color=color.red)
    ball.velocity = vector(0,-1,0)
    
    dt = 0.01
    while 1:
        rate(100)
        ball.pos = ball.pos + ball.velocity*dt
        if ball.y < 1:
            ball.velocity.y = -ball.velocity.y
        else:
            ball.velocity.y = ball.velocity.y - 9.8*dt
    Last edited by bvdet; Mar 28 '10, 02:58 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Are you wanting to embed VPython in a Tkinter application? I don't know if it is possible. I found an example where someone as done it with wxPython:


    You could try using os.popen() to call a visual window instead of execfile().

    Comment

    • Glenton
      Recognized Expert Contributor
      • Nov 2008
      • 391

      #3
      Or maybe use threads?

      Comment

      • shane12345
        New Member
        • Mar 2010
        • 4

        #4
        thanks a lot...it works

        Comment

        Working...