반응형
[python] chatGPT가 만들어준 tkinter 이용한 영화추천 프로그램
질문 : python gui program make a recomendation
import tkinter as tk
from tkinter import messagebox
# Sample movie data
movies = {
"Action": ["Die Hard", "Mad Max: Fury Road", "The Dark Knight"],
"Comedy": ["The Hangover", "Superbad", "Anchorman"],
"Drama": ["The Shawshank Redemption", "Forrest Gump", "The Godfather"]
}
def get_recommendation():
selected_genre = genre_var.get()
if selected_genre:
recommendations = movies.get(selected_genre, [])
if recommendations:
recommended_movies.set("\n".join(recommendations))
else:
recommended_movies.set("No recommendations available for this genre.")
else:
messagebox.showinfo("Error", "Please select a genre.")
# Create the main GUI window
root = tk.Tk()
root.title("Movie Recommendation")
# Create and place widgets
genre_label = tk.Label(root, text="Select a genre:")
genre_label.pack()
genre_var = tk.StringVar()
genre_dropdown = tk.OptionMenu(root, genre_var, *movies.keys())
genre_dropdown.pack()
recommend_button = tk.Button(root, text="Get Recommendation", command=get_recommendation)
recommend_button.pack()
recommended_movies = tk.StringVar()
recommended_movies_label = tk.Label(root, textvariable=recommended_movies)
recommended_movies_label.pack()
root.mainloop()
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[python] chatGPT에게 TicTacToe 만들어달라고 했다. (0) | 2023.08.21 |
---|---|
[python] send email app (0) | 2023.08.18 |
[python] PyQt5 어플리케이션 프레임워크에 대한 파이썬 버전 (0) | 2023.08.16 |
[python] 파이썬으로 만드는 나만의 GUI 프로그램. 응용프로그램 (0) | 2023.08.16 |
[python] PyInstaller Manual. 파이썬 실행파일 만들기 (0) | 2023.08.11 |