Hi, I tried to run following script of drawing a sin/cos curve using python 2.4 , there is error:

Traceback (most recent call last):
File "", line 6, in ?
File "C:\Python24\Lib\lib-tk\Tkinter.py", line 1564, in __init__
baseName = os.path.basename(sys.argv[0])
AttributeError: 'module' object has no attribute 'argv'

Can anybody tell me what should I do for this error?
Thanks!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from Tkinter import *
import math
import sys
sys.frozen = 1
 
root = Tk()
root.title("Simple plot using canvas and line")
 
width = 400
height = 300
center = height//2
x_increment = 1
# width stretch
x_factor = 0.04
# height stretch
y_amplitude = 80
 
c = Canvas(width=width, height=height, bg='white')
c.pack()
 
str1 = "sin(x)=blue  cos(x)=red"
c.create_text(10, 20, anchor=SW, text=str1)
 
center_line = c.create_line(0, center, width, center, fill='green')
 
# create the coordinate list for the sin() curve, have to be integers
xy1 = []
for x in range(400):
    # x coordinates
    xy1.append(x * x_increment)
    # y coordinates
    xy1.append(int(math.sin(x * x_factor) * y_amplitude) + center)
 
sin_line = c.create_line(xy1, fill='blue')
 
# create the coordinate list for the cos() curve
xy2 = []
for x in range(400):
    # x coordinates
    xy2.append(x * x_increment)
    # y coordinates
    xy2.append(int(math.cos(x * x_factor) * y_amplitude) + center)
 
cos_line = c.create_line(xy2, fill='red')
 
root.mainloop()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Recommended Answers

All 2 Replies

from Tkinter import *
import math
##import sys
sys.frozen = 1
.....

do you want to comment out "import sys" and try again?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.