DEV Community

dongdiri
dongdiri

Posted on

DAY23: Python day 31

Capstone Project: Flash Card App

This project was the biggest struggle by far, primarily because I was not fully proficient with all the packages.
Here are the things I should remember that may come in handy:

Pandas

  • when converting list into .csv file, make dataframe first
  • can specify file location as parameter of to_csv() function
    data = pandas.DataFrame(to_learn)
    data.to_csv("data/words_to_learn.csv")
    new_random_word()
Enter fullscreen mode Exit fullscreen mode
  • no need to use with or open when there is read_csv() function
  • dictionary becomes list when used parameter orient="records"
data = pandas.read_csv("data/french_words.csv")
to_learn = data.to_dict(orient="records")
Enter fullscreen mode Exit fullscreen mode

tkinter

  • can create text within canvas with canvas.create_text()
  • when creating text inside a canvas, keyword argument to change color is fill
card_title = canvas.create_text(400, 150, fill="black")
Enter fullscreen mode Exit fullscreen mode
  • to modify things inside canvas, first store as a variable and then use itemconfig() function
canvas.itemconfig(card_title, fill="white")
Enter fullscreen mode Exit fullscreen mode
  • use canvas.after() function to create timer without using while loop
  • canvas.after(milliseconds, function): carries out a certain function after given milliseconds -in order to prevent timer overlap, we can create a variable to store it
def new_random_word():
    global flip_timer
    canvas.after_cancel(flip_timer)
    ...
    flip_timer = canvas.after(3000, func=flip_card)
...

flip_timer = canvas.after(3000, func=flip_card)
Enter fullscreen mode Exit fullscreen mode

miscellaneous

  • .remove() function to delete item from list
  • can access files that are under the same folder without ./ or ../

Top comments (0)