0

I'm using python version 3.4.2.

I have two python script with tkinter used.

Example: one.py and two.py. Then in two.py, there will be a back button, thus when the back button is clicked, it will close the two.py and back to one.py.

This is my elif statement in one.py:

elif len(admin) == 1 and len(staff) == 0:
----open and run two.py----

In two.py:

def back():
   app.destroy()

back = Button(command=back).pack()

Is there any way i can get this going? Thank you.

noob
  • 11
  • 5

3 Answers3

0

What you want to do is import your back() function from your python file two.py. This works like so:

In your one.py, write:

import two
...  # remaining imports
# ...
elif len(admin) == 1 and len(staff) == 0:
    back = Button(commmand=two.back).pack()

Read up on what importing is and how it works here.

deepbrook
  • 2,523
  • 4
  • 28
  • 49
0

You need to pass app as parent to back button:

Example:

class app(Toplevel):
    def __init__(self, parent, *args, **kwargs):
        Toplevel.__init__(self, parent, *args, **kwargs)
        Button(self, command=self.destroy).pack()
Kenly
  • 24,317
  • 7
  • 44
  • 60
0

consider to modularize your application. modularization is pacesetter among other available options.

create an __init__.py in your project folder, where one.py and two.py is located (more about __init__.py).

one.py

import random
x = random.randint(1,5)

if x>3:
    from two import foo
    print foo(x)
else:
    print x 

two.py

def foo(x):
    return "fooed:", x,

run

$ python one.py 
('fooed:', 5)
$ python one.py 
1
Community
  • 1
  • 1
marmeladze
  • 6,468
  • 3
  • 24
  • 45