图形展示
代码
里面判断图形是否重合做的有点糙,好多判断不出来,勉强可以用。
import tkinter
from tkinter import *
import random
import time
def painting():
start_point_x = random.randint(1, 640)
start_point_y = random.randint(31, 340)
end_point_x = start_point_x + 30
end_point_y = start_point_y + 30
return start_point_x, start_point_y, end_point_x, end_point_y
class games1:
def __init__(self):
self.win = tkinter.Tk()
self.win.title("判断图像个数")
self.win.geometry("760x430")
# 创建并添加画布
self.cv = Canvas(self.win, background='white')
self.cv.pack(fill=BOTH, expand=YES)
# 添加提示信息
label1 = '*' * 50 + "请问刚才出现了几个图形?" + '*' * 50
self.label1 = tkinter.Label(self.win, text=label1)
self.label1.place(x=1, y=1)
# 添加清除画布按钮
self.button1 = tkinter.Button(self.win, text="重置", width=8, command=self.refresh_data).place(x=680, y=30)
self.button2 = tkinter.Button(self.win, text="清除", width=8, command=self.clear_all).place(x=680, y=80)
# 添加验证输入框和验证按钮
self.label2 = tkinter.Label(self.win, text="矩形个数").place(x=680, y=130)
self.entry2 = tkinter.Entry(self.win, width=8