In my programming class I am learning how to make graphical user interfaces, and so I decided to make one.
import tkinter as t
from random import choice
COLORS = ["white", "black", "red", "green", "blue", "cyan", "yellow", "magenta"]
def button_clicked():
display_area.config(text = "You clicked the button!")
screen.itemconfig(epilepsy_man, fill = choice(COLORS))
def epilepsy_man_movment(event):
key = event.keysym
if key == "Right":
screen.move(epilepsy_man, 10, 0)
screen.itemconfig(epilepsy_man, fill = choice(COLORS))
elif key == "Left":
screen.move(epilepsy_man, -10, 0)
screen.itemconfig(epilepsy_man, fill = choice(COLORS))
elif key == "Up":
screen.move(epilepsy_man, 0, -10)
screen.itemconfig(epilepsy_man, fill = choice(COLORS))
elif key == "Down":
screen.move(epilepsy_man, 0, 10)
screen.itemconfig(epilepsy_man, fill = choice(COLORS))
window = t.Tk()
window.title("Your reading this right now. Please stop.")
button = t.Button(window, text = "Can you click me?", command = button_clicked)
button.pack()
display_area = t.Label(window, text = "Go on! Click the button!")
display_area.pack()
screen = t.Canvas(window, width = 500, height = 500)
screen.pack()
epilepsy_man = screen.create_oval(200, 200, 300, 300, fill = choice(COLORS))
screen.bind_all("<Key>", epilepsy_man_movment)
window.mainloop()
Please note "epilepsy". If you run this there will be flashing images.
I want to know if I properly followed any conventions, as well as if there is any better way of doing what I have done.
What this program does is make a button that changes the color of the circle and the text on a textbox, as well as creating said textbox and said circle which moves with the arrow keys and changes with each key press.