我想知道如果有人做出另一个选择,我将如何重置应用程序。当你运行我的代码时,你会看到当我选择一个类型它工作正常但如果我选择另一个它在同一窗口中运行另一个实例。我希望用户能够循环播放流派并观看不同的电影。
from tkinter import *
class movie1:
def __init__(self, master):
self.master = master
master.title("Movie Recommendation")
self.label = Label(master, text= "Welcome to the movie recommendation application! \n Please select the genre of the movie you would like to see.", fg='snow', bg='dark slate gray')
self.label.pack(padx=25, pady=25)
v = StringVar()
c1 = self.radiobutton = Radiobutton(master, text = "Action", variable=v, value=1, bg='cyan3', command=self.reco1)
c1.pack(side=TOP, padx=10, pady=10)
c2 = self.radiobutton = Radiobutton(master, text = "Comedy", variable=v, value=2, bg='cyan3', command=self.reco2)
c2.pack(side=TOP, padx=10, pady=10)
c3 = self.radiobutton = Radiobutton(master, text = "Documentary", variable=v, value=3, bg='cyan3', command=self.reco3)
c3.pack(side=TOP, padx=10, pady=10)
c4 = self.radiobutton = Radiobutton(master, text = "Horror", variable=v, value=4, bg='cyan3', command=self.reco4)
c4.pack(side=TOP, padx=10, pady=10)
c5 = self.radiobutton = Radiobutton(master, text = "Romance", variable=v, value=5, bg='cyan3', command=self.reco5)
c5.pack(side=TOP, padx=10, pady=10)
def reco1(self):
y = StringVar()
self.canvas = Canvas(width=200, height=200)
self.canvas.pack( expand=YES, pady=20)
gif1 = PhotoImage(file="movie1.gif")
self.canvas.create_image(100,100,image=gif1)
self.canvas.gif1 = gif1
label = Message (root, textvariable=y)
y.set("Would you like to watch this movie?")
label.pack()
self.radiobutton = Radiobutton(text = "YES", variable=y, command = self.choice1)
self.radiobutton.pack(side=LEFT)
self.radiobutton = Radiobutton(text = "NO", variable=y, command = self.choice2)
self.radiobutton.pack(side=RIGHT)
def reco2(self):
y = StringVar()
self.canvas = Canvas(width=200, height=200)
self.canvas.pack( expand=YES, pady=20)
gif1 = PhotoImage(file="Movies/movie1.gif")
self.canvas.create_image(100,100,image=gif1)
self.canvas.gif1 = gif1
label = Message (root, textvariable=y)
y.set("Would you like to watch this movie?")
label.pack()
self.radiobutton = Radiobutton(text = "YES", variable=y, command = self.choice1)
self.radiobutton.pack(side=LEFT)
self.radiobutton = Radiobutton(text = "NO", variable=y, command = self.choice2)
self.radiobutton.pack(side=RIGHT)
reco2.loop()
def reco3(self):
y = StringVar()
self.canvas = Canvas(width=200, height=200)
self.canvas.pack( expand=YES, pady=20)
gif1 = PhotoImage(file="Movies/movie1.gif")
self.canvas.create_image(100,100,image=gif1)
self.canvas.gif1 = gif1
label = Message (root, textvariable=y)
y.set("Would you like to watch this movie?")
label.pack()
self.radiobutton = Radiobutton(text = "YES", variable=y, command = self.choice1)
self.radiobutton.pack(side=LEFT)
self.radiobutton = Radiobutton(text = "NO", variable=y, command = self.choice2)
self.radiobutton.pack(side=RIGHT)
def reco4(self):
y = StringVar()
self.canvas = Canvas(width=200, height=200)
self.canvas.pack( expand=YES, pady=20)
gif1 = PhotoImage(file="Movies/movie1.gif")
self.canvas.create_image(100,100,image=gif1)
self.canvas.gif1 = gif1
label = Message (root, textvariable=y)
y.set("Would you like to watch this movie?")
label.pack()
self.radiobutton = Radiobutton(text = "YES", variable=y, command = self.choice1)
self.radiobutton.pack(side=LEFT)
self.radiobutton = Radiobutton(text = "NO", variable=y, command = self.choice2)
self.radiobutton.pack(side=RIGHT)
def reco5(self):
y = StringVar()
self.canvas = Canvas(width=200, height=200)
self.canvas.pack( expand=YES, pady=20)
gif1 = PhotoImage(file="Movies/movie1.gif")
self.canvas.create_image(100,100,image=gif1)
self.canvas.gif1 = gif1
label = Message (root, textvariable=y)
y.set("Would you like to watch this movie?")
label.pack()
self.radiobutton = Radiobutton(text = "YES", variable=y, command = self.choice1)
self.radiobutton.pack(side=LEFT)
self.radiobutton = Radiobutton(text = "NO", variable=y, command = self.choice2)
self.radiobutton.pack(side=RIGHT)
def choice1(self):
messagebox.showinfo("Grab your popcorn and enjoy the movie!")
def choice2(self):
messagebox.showinfo("I'm sorry, click the button to end the program and try again!")
root.destroy()
root = Tk()
root.configure(bg='cyan3')
my_gui = movie1(root)
root.mainloop()