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.

2
  • So you want to run one.py and two.py as separate programs? Commented Dec 1, 2016 at 8:56
  • @J.P.Petersen yes. it's like a front end and back end program Commented Dec 1, 2016 at 9:13

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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()

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.