from tkinter import *
class Canvas1(Frame):
def __init__(self):
"""Sets up the window and widgets."""
Frame.__init__(self)
self.master.title("GUIs drawing geometric shapes")
self.grid()
#Create a canvas and place in this frame
self.canvas = Canvas(self, width = 500, height = 400, bg = "white")
self.canvas.grid(row = 0, column = 0)
#Place buttons in a frame
frame = Frame(self)
frame.grid(row = 1, column = 0)
self.v1 = IntVar()
rectangle = Radiobutton(frame, text = "Rectangle", variable = self.v1,
value = 1, command = self.displayRectangle)
oval = Radiobutton(frame, text = "Oval", variable = self.v1,
value = 2, command = self.displayOval)
self.is_checked = IntVar()
filled = Checkbutton(frame, text = "Filled", onvalue = 1, offvalue = 0, variable = self.is_checked, command = self.displayFilled)
clear = Button(frame, text = "Clear", command = self.clearCanvas)
rectangle.grid(row = 0, column = 0)
oval.grid(row = 0, column = 1)
filled.grid(row = 0, column = 2)
clear.grid(row = 0, column = 3)
def displayRectangle(self):
self.canvas.create_rectangle(50, 50, 250, 250, tags = "rect")
if self.is_checked.get():
displayFilled()
def displayOval(self):
self.canvas.create_oval(50, 100, 250, 200, tags = "oval")
def displayFilled(self):
if(self.v1.get() == 1):
self.canvas.create_rectangle(50, 50, 250, 250, fill = "red", tags = "rect")
if(self.v1.get() == 2):
self.canvas.create_oval(50, 100, 250, 200, fill = "yellow", tags = "oval")
def clearCanvas(self):
self.canvas.delete("rect", "oval", "filled")
self.v1.set(3)
self.is_checked.set(2)
def main():
Canvas1().mainloop()
main()
//
2번쨰그림 빨간색 출력안되는데 뭐 수정해야됨?
댓글 0