TypeError: unsupported operand type(s) for -: 'str' and 'str'
Написал функцию DrawLine в tkinter, но при её использовании появляется ошибка:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
С чем она может быть связана?
Код:
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from tkinter import *
window = Tk()
img=np.ones((1000,1000,3))
def DrawLine(x1, y1, x2, y2):
dx=abs(x2-x1)
dy=abs(y2-y1)
if x1<x2:
xs=1
else:
xs=-1
if y1<y2:
ys=1
else:
ys=-1
x=x1
y=y1
if dx>dy:
p=2*y-dx
while x!=x2:
x=x+xs
if p>0:
y=y+ys
p=p+2*dy-2*dx
else:
p=p+2*dy
img[y,x]=0
else:
p=2*x-dy
while y!=y2:
y=y+ys
if p>0:
x=x+xs
p=p+2*dx-2*dy
else:
p=p+2*dx
img[y,x]=0
def clicked():
a = txt.get()
b = txt2.get()
c = txt3.get()
d = txt4.get()
plt.rcParams["figure.figsize"]=(5,5)
plt.rcParams["figure.dpi"]=80
DrawLine(a,b,c,d)
plt.imshow(img)
plt.show()
window.title("Programma")
window.geometry('350x300+600+200')
txt = Entry(window,width=30)
txt.grid(column = 2, row = 0)
lbl = Label(window, text = "Введите координату x1")
lbl.grid(column = 1, row = 0)
txt2 = Entry(window,width=30)
txt2.grid(column = 2, row = 1)
lbl2 = Label(window, text = "Введите координату y1")
lbl2.grid(column = 1, row = 1)
txt3 = Entry(window,width=30)
txt3.grid(column = 2, row = 2)
lbl3 = Label(window, text = "Введите координату x2")
lbl3.grid(column = 1, row = 2)
txt4 = Entry(window,width=30)
txt4.grid(column = 2, row = 3)
lbl4 = Label(window, text = "Введите координату y1")
lbl4.grid(column = 1, row = 3)
btn = Button(window, text = "Нажми на меня", command=clicked)
btn.grid(column = 1, row = 4)
window.mainloop()