root = Tk() #create a root widget root.title("TK") #set title root.geometry("600x400+20+20") #set window with 600x400 pixcel, left-up corner in position (20,20) frm = ttk.Frame(root, padding=10) #create a frame based on root frm.grid() #easy placement based on column and row
lb=ttk.Label(frm, text="Label") #label box lb.grid(row=0,column=0) #pack label into grid
entry=ttk.Entry(frm) #enter box enter.delete(0,"end") #remove contents enter.insert(0,"insert") #input string "Insert" in enter box enter.grid(row=0,column=1)
Can=Canvas(frm,height=300,width=200) #create a canvas cell=Canvas.create_rectangle(2, 2, 20, 20, fill = "black") #a reactangle filled with black, in range (2,2) to (20,20) Can.delete(ALL) #remove all copoments in canvas
Can.bind("<ButtonPress-1>",mouse_event) #mouse event and commanf funciton
def mouse_event(event): lb.config(text=event) #change label text
root.after(300,mouse_event) #repeat mouse_event function after 300ms