-
Notifications
You must be signed in to change notification settings - Fork 3
/
Assignment10_1.py
47 lines (41 loc) · 1.34 KB
/
Assignment10_1.py
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
'''
Created on Jun 5, 2015
A GUI application, which displays a window for reading the width and height of
a shape and then draws it. The shape can be either a rectangle or an oval and
it should also be read from an Entry widget.
@author: lebs
'''
from tkinter import *
def drawRectangle():
global shapeEntry, canvas
canvas.pack_forget()
shape = shapeEntry.get()
width = shape.split(',')[0]
height = shape.split(',')[1]
canvas=Canvas(root, height=300, width=400)
canvas.create_rectangle(10,10,eval(width),eval(height))
canvas.pack()
def drawOval():
global shapeEntry, canvas
canvas.pack_forget()
shape = shapeEntry.get()
width = shape.split(',')[0]
height = shape.split(',')[1]
canvas=Canvas(root, height=300, width=400)
canvas.create_oval(10,10,eval(width),eval(height))
canvas.pack()
if __name__ == '__main__':
root = Tk()
root.wm_title('Draw')
root.geometry('400x400+50+60')
root.resizable(width=True, height=False)
label=Label(root, text='Enter width,height:')
label.pack()
shapeEntry=Entry(root)
shapeEntry.pack()
canvas=Canvas(root, height=300, width=400)
button1=Button(root, text='Rectangle', command=drawRectangle)
button2=Button(root, text='oval', command=drawOval)
button1.pack()
button2.pack()
root.mainloop()