Skip to content

Instantly share code, notes, and snippets.

@oiojin831
Created August 29, 2021 05:01
Show Gist options
  • Save oiojin831/e72e352cc1bcb55e2d928da4d3bbe8fd to your computer and use it in GitHub Desktop.
Save oiojin831/e72e352cc1bcb55e2d928da4d3bbe8fd to your computer and use it in GitHub Desktop.
from tkinter import *
import random
movies = []
def click():
global movies
movies.append({"title": title_entry.get(), "director": director_entry.get()})
click_label = Label(window, text="새로운 영화가 추가됐습니다.")
click_label.pack()
def show_all():
global movies
for x in movies:
l = Label(window, text=f"{x['title']}의 감독은 {x['director']}입니다")
l.pack()
def random_movie():
global movies
my_movie = random.choice(movies)
l = Label(window, text=f"내 랜덤 영화는 {my_movie['title']}의 감독은 {my_movie['director']}입니다")
l.pack()
window = Tk()
window.title("my tk app")
window.geometry("600x600")
window.configure(background="green")
title_entry = Entry(window)
director_entry = Entry(window)
my_button = Button(window,text="영화 추가", command=click)
show_all_button = Button(window,text="영화 전부 보기", command=show_all)
random_button = Button(window,text="영화 랜덤 고르기", command=random_movie)
title_entry.pack()
director_entry.pack()
my_button.pack()
show_all_button.pack()
random_button.pack()
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment