0
\$\begingroup\$

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.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Can I have a better explanation of the close vote and the downvotes? \$\endgroup\$
    – user211881
    Commented Mar 11, 2020 at 19:50
  • 3
    \$\begingroup\$ Most likely due to lack of details about this program. What is its purpose? What specific improvements are you looking for? The more detail about your program, the better. \$\endgroup\$
    – Linny
    Commented Mar 11, 2020 at 20:06

1 Answer 1

3
\$\begingroup\$

You misspelled "movement" as "movment".

Typically (as per PEP-8), indentations are specified by one hard tab or four spaces, so you're good in that respect.

To be sure about formatting you can read up on PEP-8.

I am also wondering about _man. This doesn't seem to be displaying a man (but I haven't run it) so why name it that way? Also, epilepsy doesn't seem like a suitable name. Perhaps colored_box would be more formal?

\$\endgroup\$
4
  • \$\begingroup\$ Why the downvote? \$\endgroup\$
    – S.S. Anne
    Commented Mar 11, 2020 at 19:58
  • \$\begingroup\$ I downvoted because I felt that it did not add anything as it seemed to me the only feedback you gave for me is that I misspelled a word. \$\endgroup\$
    – user211881
    Commented Mar 11, 2020 at 20:16
  • 1
    \$\begingroup\$ @K00lman Thanks for the feedback. I wouldn't have pointed it out if I didn't feel it was important. Typos might make you look bad to the professor. \$\endgroup\$
    – S.S. Anne
    Commented Mar 11, 2020 at 20:23
  • 1
    \$\begingroup\$ Thanks for that, but this is just something I made in my free time to make sure I get what is being taught. It is not going to be used in my class at all. As such, it's not the most formal. \$\endgroup\$
    – user211881
    Commented Mar 11, 2020 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.