0
我正在python中構建一個非常基礎的電影推薦GUI,我試圖讓它在選擇流派時打開一個新窗口。我可以打開窗口,但我無法將單選按鈕分配給新班級。我希望能夠選擇一種流派,然後點擊下一步,並根據用戶選擇的按鈕開始我的推薦。在tkinter GUI中使用多個窗口
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.")
self.label.pack(padx=25, pady=25)
CheckVar1 = StringVar()
C1 = Radiobutton(master, text = "Action", variable = CheckVar1, value=1)
C1.pack(side=TOP, padx=10, pady=10)
C2 = Radiobutton(master, text = "Comedy", variable = CheckVar1, value=2)
C2.pack(side=TOP, padx=10, pady=10)
C3 = Radiobutton(master, text = "Documentary", variable = CheckVar1, value=3)
C3.pack(side=TOP, padx=10, pady=10)
C4 = Radiobutton(master, text = "Horror", variable = CheckVar1, value=4)
C4.pack(side=TOP, padx=10, pady=10)
C5 = Radiobutton(master, text = "Romance", variable = CheckVar1, value=5)
C5.pack(side=TOP, padx=10, pady=10)
self.nextbutton = Button(master, text="Next", command=self.reco)
self.nextbutton.pack(side=BOTTOM, padx=10, pady=10)
def reco(self):
self.newWindow = Toplevel(self.master)
self.app = movie2(self.newWindow)
class movie2:
def __init__(self, master):
self.master = master
self.frame = Frame(self.master)
def C1(self):
print("option 1")
root = Tk()
my_gui = movie1(root)
root.mainloop()
*我希望能夠選擇一個流派,點擊下一步,並基於此按鈕,用戶選擇與我的建議開始* - 如果你的意思是你想讓第二類知道選擇了什麼,只需將它發送到movie2,那麼self.app = movie2(self.newWindow,genre_selected) –