python - How to pass coordinates as arguments to a function? -


the following code , when executed get:

typeerror: __init__() missing 1 required positional argument: 'y' 

this code:

def drawuppercaset(win, location1):      lettert = text(point(location1), "t")     lettert.setsize(30)     lettert.draw(win)  def main():      #1. create graphics window     win = graphwin("my initials", 600, 600)     win.setcoords(0,0,100,100)     location1 = (15,50)      drawuppercaset(win, location1)      #capture mouse close     win.getmouse()     win.close()  main() 

when put code function in main method works. when try implement separately , pass location1 argument drawuppercaset, error. seems maybe y coordinate getting lost or something. can please explain need working?

from can see ducking, point constructor doesn't take tuple. instead requires separate x , y parameters: point(x, y)

you can either replace location parameter 2 individual parameters; so:

def drawuppercaset (win, x, y): 

or extract tuple members; so:

... point(location1[0], location1[1]) ... 

or flatten tuple during call:

... point(*location1) ... 

i recommend flattening because (1) it's cool; (2) tuples make more sense separate coordinate values; , (3) it's cool!


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -