-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path166 hw..py
More file actions
76 lines (63 loc) · 2.35 KB
/
166 hw..py
File metadata and controls
76 lines (63 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image
root= Tk()
root.title("Working On Canvas Using Functions")
root.geometry("600x600")
canvas= Canvas(root, height=900,width=900,bg="white",highlightbackground="lightgray")
canvas.pack()
color_label=Label(root, text="Choose a Color :")
color_label.place(relx=0.6,rely=0.9, anchor= CENTER)
fill_color=["green","yellow","red","blue"]
colour_dropdown= ttk.Combobox(root, state="readonly",values= fill_color ,width=10)
colour_dropdown.place(relx=0.8,rely=0.9,anchor=CENTER)
startx=Label(root,text="startx")
startx.place(relx=0.1,rely=0.85,anchor=CENTER)
coordinate_valus=[10,50,100,200,300,400,500,600,700,800,900]
d1= ttk.Combobox(root, state="readonly",values= coordinate_valus ,width=10)
d1.place(relx=0.2,rely=0.85,anchor=CENTER)
starty=Label(root,text="starty")
starty.place(relx=0.3,rely=0.85,anchor=CENTER)
d2= ttk.Combobox(root, state="readonly",values= coordinate_valus ,width=10)
d2.place(relx=0.4,rely=0.85,anchor=CENTER)
endx=Label(root,text="endx")
endx.place(relx=0.5,rely=0.85,anchor=CENTER)
d3= ttk.Combobox(root, state="readonly",values= coordinate_valus ,width=10)
d3.place(relx=0.6,rely=0.85,anchor=CENTER)
endy=Label(root,text="endy")
endy.place(relx=0.7,rely=0.85,anchor=CENTER)
d4= ttk.Combobox(root, state="readonly",values= coordinate_valus ,width=10)
d4.place(relx=0.8,rely=0.85,anchor=CENTER)
def circle(event):
oldx= d1.get()
oldy= d2.get()
newx= d3.get()
newy= d4.get()
keypress= 'c'
draw(keypress,oldx,oldy,newx,newy)
def rectangle(event):
oldx= d1.get()
oldy= d2.get()
newx= d3.get()
newy= d4.get()
keypress= 'r'
draw(keypress,oldx,oldy,newx,newy)
def line(event):
oldx= d1.get()
oldy= d2.get()
newx= d3.get()
newy= d4.get()
keypress= 'l'
draw(keypress,oldx,oldy,newx,newy)
def draw(keypress,oldx,oldy,newx,newy):
color= colour_dropdown.get()
if keypress=='c':
draw_circle= canvas.create_oval(oldx,oldy,newx,newy, fill=color)
if keypress=='r':
draw_rectangle= canvas.create_rectangle(oldx,oldy,newx,newy, fill=color)
if keypress=='l':
draw_line= canvas.create_line(oldx,oldy,newx,newy, fill=color)
root.bind("<c>",circle)
root.bind("<r>",rectangle)
root.bind("<l>",line)
root.mainloop()