我正在尝试在tkinter的画布上制作两个正方形,然后检查它们的共享空间是多少。我写了这个剧本:
from tkinter import *
a1=int(input("enter cord x1: "))
b1=int(input("enter cord y1: "))
n=int(input("enter len 1: "))
a2=int(input("enter cord x2: "))
b2=int(input("enter cord y2: "))
m=int(input("enter len 2: "))
t1=a1+n
g1=b1+n
t2=a2+m
g2=b2+m
master = Tk()
w = Canvas(master, width=2500, height=2000)
w.create_rectangle(a1, b1, t1, g1, fill="blue", outline = 'black')
w.create_rectangle(a2, b2, t2, g2, fill="red", outline = 'black')
w.pack()
def fun(m,n,a1,b1,a2,b2):
if a1 < a2 and a1+n > a2:
if b1 < b2 and b1+n > b2:
sx=(a1+n-a2)
sy=(b1+n-b2)
ts=(sx*sy)
print ("The shared space is " + str(ts) + " squared pixels!")
else:
print ("No Shared Space! please try again")
else:
print ("No Shared Space! please try again")
fun(m,n,a1,b1,a2,b2)
master.mainloop()
我已经用几个数字测试了它,但是我无法在计算机上使用tkinter而且我在脑海中进行了计算。请告诉我它是否应该有用。