Hi guys. I'm new to python, so go easy.
Heres my problem. I've got my main file, Python Paint.py -
#Python Paint.py
-
from graphics import *
-
import time
-
import functions
-
-
win = GraphWin("Python Paint",600,600)
-
win.setCoords(-100.0,-100.0,100.0,100.0)
-
mycolor = "red"
-
center = Point(0,95)
-
-
functions.tri()
-
-
as you can see, I import another file I've written, called functions.py
-
here it is:
-
-
#functions.py
-
from graphics import *
-
import time
-
-
def tri():
-
direc = Text(center, "Click three points to form a triangle")
-
direc.draw(win)
-
time.sleep(2)
-
direc.undraw()
-
click1 = win.getMouse()
-
click2 = win.getMouse()
-
click3 = win.getMouse()
-
triang = Polygon(click1,click2,click3)
-
triang.setFill(mycolor)
-
triang.draw(win)
-
tri()
I assign variables in my Python Paint file, but when i try to call these variables in my functions file, I get an error. Is there any way I can use variables from my main file in my functions file? I hope I've explained this properly.
3 2123
Hi guys. I'm new to python, so go easy.
Heres my problem. I've got my main file, Python Paint.py -
#Python Paint.py
-
from graphics import *
-
import time
-
import functions
-
-
win = GraphWin("Python Paint",600,600)
-
win.setCoords(-100.0,-100.0,100.0,100.0)
-
mycolor = "red"
-
center = Point(0,95)
-
-
functions.tri()
-
-
as you can see, I import another file I've written, called functions.py
-
here it is:
-
-
#functions.py
-
from graphics import *
-
import time
-
-
def tri():
-
direc = Text(center, "Click three points to form a triangle")
-
direc.draw(win)
-
time.sleep(2)
-
direc.undraw()
-
click1 = win.getMouse()
-
click2 = win.getMouse()
-
click3 = win.getMouse()
-
triang = Polygon(click1,click2,click3)
-
triang.setFill(mycolor)
-
triang.draw(win)
-
tri()
I assign variables in my Python Paint file, but when i try to call these variables in my functions file, I get an error. Is there any way I can use variables from my main file in my functions file? I hope I've explained this properly.
-
#Python Paint.py
-
from graphics import *
-
import time
-
import functions
-
-
win = GraphWin("Python Paint",600,600)
-
win.setCoords(-100.0,-100.0,100.0,100.0)
-
mycolor = "red"
-
center = Point(0,95)
-
-
functions.tri(win)
-
-
as you can see, I import another file I've written, called functions.py
-
here it is:
-
-
#functions.py
-
from graphics import *
-
import time
-
-
def tri(win):
-
direc = Text(center, "Click three points to form a triangle")
-
direc.draw(win)
-
time.sleep(2)
-
direc.undraw()
-
click1 = win.getMouse()
-
click2 = win.getMouse()
-
click3 = win.getMouse()
-
triang = Polygon(click1,click2,click3)
-
triang.setFill(mycolor)
-
triang.draw(win)
-
if __name__ == "__main__":
-
win = GraphWin("Python Paint",600,600)
-
tri(win)
-
#
Pass what you need in the parameters.
That last part eliminates import problems and allows you to test the module.
I still get this error when I try that:
NameError: name 'win' is not defined
I still get this error when I try that:
NameError: name 'win' is not defined
That can happen if you are trying to run in an interactive window using "import".
If you are using
>>> import themodule
The try
>>> reload(themodule)
Then we'll discuss better way to run your programs.
Or perhaps, simply post your modified code here (instructions for using CODE tags are on the right hand side of the page).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Torsten Bronger |
last post by:
Hallöchen!
I have a file that looks a little bit like a C header file with a
long list of variables (actually constants) definitions, e.g.
VI_ATTR_TIMO = 0x54378
....
Actually I need this...
|
by: Michael Brenner |
last post by:
Hi,
I'm implementing a plugin-based program, structured like the example
below (where m1 in the main module, loading m2 as a plugin). I wanted
to use a single global variable (m1.glob in the...
|
by: jmalone |
last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has
AIX and does not want to install Python). The python script is pretty
simple (the only things it imports are sys and socket)....
|
by: cjt22 |
last post by:
Hi
I am new to Python (I have come from a large background of Java) and
wondered if someone could explain to me how I can access variables
stored in my main module to other functions within...
|
by: icarus |
last post by:
global_vars.py has the global variables
set_var.py changes one of the values on the global variables (don't
close it or terminate)
get_var.py retrieves the recently value changed (triggered right...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |