python 3.x - How to make functions that draw lines in canvas (tkinter 3.x) properly -


i making program draws line(you decide beggining , end of sliders/scales), problem im getting these errors(that wish understood) when press psy button(code below errors) :

exception in tkinter callback traceback (most recent call last):   file "c:\python351\lib\tkinter\__init__.py", line 1549, in __call__     return self.func(*args)   file "c:/users/koteu/pycharmprojects/guji/fsd.py", line 23, in creat     cans.create_line(ar1,ar2,br1,br2)   file "c:\python351\lib\tkinter\__init__.py", line 2331, in create_line     return self._create('line', args, kw)   file "c:\python351\lib\tkinter\__init__.py", line 2319, in _create     *(args + self._options(cnf, kw)))) _tkinter.tclerror: bad screen distance ".14855536.14855504"  process finished exit code 0 

anyways, code :

import os import sys tkinter import * root = tk() app=frame(root)  root.geometry("1200x1200") ar1 = scale(root,from_=0,to=600) ar2= scale(app,from_=0,to=600,deafultvar=0)#app instead of root because button unknown me reason  #wouldn't appear in gui otherwise br1= scale(root,from_=0,to=600) br2= scale(root,from_=0,to=600)      cans = canvas(root,width = 500,height = 500)  cans.create_line(600,50,0,50) #this has nothing actual program understanding   def creat():     cans.create_line(ar1,ar2,br1,br2)#< causes problem don't understand    psy=button(root,command=creat,text="karole") psy.pack() cans.pack() ar1.pack() ar2.pack() br1.pack() br2.pack()  mainloop() 

also, if helps, im using py345

cans.create_line(x0, y0, ...) takes number of integer coordinates positional args. passed widgets, turned string identifiers. in ".14855536.14855504", '.' represents root, '14855536' canvas, , '14855504' scale ar1. instead need use .get() method on scales integer values. following works.

from tkinter import * root = tk()  root.geometry("1200x1200") ar1 = scale(root,from_=0,to=600) ar2= scale(root,from_=0, to=600) br1= scale(root,from_=0, to=600) br2= scale(root,from_=0, to=600)  cans = canvas(root, width=500, height=500)  def creat():     cans.create_line(ar1.get(), ar2.get(), br1.get(), br2.get()) psy=button(root, command=creat, text="karole") ar1.pack() ar2.pack() br1.pack() br2.pack() psy.pack() cans.pack()  root.mainloop() 

a couple of other fixes: defaultvar option not valid , caused error; mainloop() instead of root.mainloop() caused tk create second tk object, bad idea.

edit: added code works.


Comments