PYTHON only Please help with the following problem 93 Select

PYTHON only! Please help with the following problem:

9.3 (Select geometric figures) Write a program that draws a rectangle or an oval, as shown in Figure 9.23. The user selects a figure from a radio button and specifies whether it is filled by selecting a check button.

Solution

try:
# for Python2
from Tkinter import *
except ImportError:
# for Python3
from tkinter import *


class geometricFig:
def __init__(self):
window = Tk()
window.title(\"Geometric Figures\")

self.canvas = Canvas(window, width = 200, height = 100, bg = \"white\")
self.canvas.pack()

frame = Frame(window)
frame.pack()
self.v1 = StringVar()
self.v2 = StringVar()
rbRect = Radiobutton(frame, text = \"Rectangle\", command = self.processFill, variable = self.v1, value = \'1\')
rbOval = Radiobutton(frame, text = \"Oval\", command = self.processFill, variable = self.v1, value = \'2\')
cbtFill = Checkbutton(frame, text = \"Fill\", command = self.processFill, variable = self.v2)
rbRect.grid(row = 1, column = 1)
rbOval.grid(row = 1, column = 2)
cbtFill.grid(row = 1, column = 3)

window.mainloop()

def processFill(self):
color = \"white\" if self.v2.get() == \"0\" else \"black\"
if self.v1.get() == \'1\':
self.canvas.delete(\"rect\", \"oval\")
self.canvas.create_rectangle(10, 10, 190, 90, tags = \"rect\", fill = color)
elif self.v1.get() == \'2\':
self.canvas.delete(\"rect\", \"oval\")
self.canvas.create_oval(10, 10, 190, 90, tags = \"oval\", fill = color)
else:
self.canvas.delete(\"rect\", \"oval\")


geometricFig()

PYTHON only! Please help with the following problem: 9.3 (Select geometric figures) Write a program that draws a rectangle or an oval, as shown in Figure 9.23.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site