I need help writing a code in python. I need to write a code for a GUI. I got th
ID: 655697 • Letter: I
Question
I need help writing a code in python. I need to write a code for a GUI. I got the canvas to show up but the rest I am having trouble with.
I need a line of 20 pixels long and 6 pixels wide is drawn at the center of the canvas, starting at 10 pixels from the bottom edge. When the user presses the left arrow, the line turns pi / 20 to the left and with the right arrow, the line turns pi / 20 to the right. When the user presses the up arrow, a red ray is drawn from the line. The ray is 200 pixels long and one pixel wide.
This is What I have so far and I need to use classes:
from Tkinter import tkinter, Tk, Label, Canvas, Scale, DoubleVar
class Spotter (object):
def __init__(self, wdw):
wdw.title("spotter with key bindings")
self.cnv=Canvas(wdw, width=400, height=200, bg='white')
self.cnv.pack()
def draw_rec(self):
self.cnv.create_rectangle(197, 203, 10, 30, outline="black", fill='black')
def main():
top = Tk()
spo=Spotter(top)
top.mainloop()
if __name__ == "__main__":
main()
I need something that looks like this:
Explanation / Answer
You need to add following lines of code to get required o/p
self.can.create_line(0, 0, 0, 6, fill="#000", width=6)
self.can.create_line(0, 0, 0, 200, fill="#FFC0CB", width=1)